Skip to content

Commit

Permalink
[docs] Link between sections
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Apr 2, 2017
1 parent 567a35e commit d6d09bc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</head>
<body>
<div id="app"></div>
<script src="../build/dll.bundle.js"></script>
<script src="build/bundle.js"></script>
<script src="/build/dll.bundle.js"></script>
<script src="/build/bundle.js"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions docs/src/components/AppRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import React from 'react';
import {
applyRouterMiddleware,
hashHistory,
browserHistory,
Router,
Route,
IndexRoute,
Expand All @@ -20,7 +20,7 @@ import { componentAPIs, requireMarkdown, demos, requireDemo } from 'docs/src/com
export default function AppRouter() {
return (
<Router
history={hashHistory}
history={browserHistory}
render={applyRouterMiddleware(useScroll())}
>
<Route title="Material UI" path="/" component={AppFrame}>
Expand Down
37 changes: 37 additions & 0 deletions docs/src/components/MarkdownElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ import marked from 'marked';
import customPropTypes from 'material-ui/utils/customPropTypes';
import prism from 'docs/src/utils/prism';

const renderer = new marked.Renderer();

renderer.heading = (text, level) => {
const escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');

return `
<h${level}>
<a class="anchor-link" id="${escapedText}"></a>${
text
}<a class="anchor-link-style" href="#${escapedText}">${
'#'
}</a>
</h${level}>
`;
};

marked.setOptions({
gfm: true,
tables: true,
Expand All @@ -18,13 +34,31 @@ marked.setOptions({
highlight(code) {
return prism.highlight(code, prism.languages.jsx);
},
renderer,
});

const anchorLinkStyle = (theme) => ({
'& .anchor-link-style': {
display: 'none',
},
'&:hover .anchor-link-style': {
display: 'inline',
fontSize: '0.8em',
lineHeight: '1',
paddingLeft: theme.spacing.unit,
color: theme.palette.text.hint,
},
});

const styleSheet = createStyleSheet('MarkdownElement', (theme) => ({
root: {
marginTop: theme.spacing.unit * 2,
marginBottom: theme.spacing.unit * 2,
padding: '0 10px',
'& .anchor-link': {
marginTop: -theme.spacing.unit * 12, // Offset for the anchor.
position: 'absolute',
},
'& pre': {
margin: '25px 0',
padding: '12px 18px',
Expand All @@ -44,16 +78,19 @@ const styleSheet = createStyleSheet('MarkdownElement', (theme) => ({
...theme.typography.display2,
color: theme.palette.text.secondary,
margin: '0.7em 0',
...anchorLinkStyle(theme),
},
'& h2': {
...theme.typography.display1,
color: theme.palette.text.secondary,
margin: '1em 0 0.7em',
...anchorLinkStyle(theme),
},
'& h3': {
...theme.typography.headline,
color: theme.palette.text.secondary,
margin: '1em 0 0.7em',
...anchorLinkStyle(theme),
},
'& p, & ul, & ol': {
lineHeight: 1.6,
Expand Down
2 changes: 1 addition & 1 deletion docs/webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = Object.assign({}, webpackBaseConfig, {
output: {
path: path.join(__dirname, 'build'),
filename: 'bundle.js',
publicPath: 'build/',
publicPath: '/build/',
},
module: {
rules: [
Expand Down

0 comments on commit d6d09bc

Please sign in to comment.