diff --git a/build.js b/build.js index ff9b3d108e50d..ad1ffcd987876 100755 --- a/build.js +++ b/build.js @@ -11,6 +11,7 @@ const markdown = require('metalsmith-markdown'); const prism = require('metalsmith-prism'); const stylus = require('metalsmith-stylus'); const permalinks = require('metalsmith-permalinks'); +const marked = require('marked'); const path = require('path'); const fs = require('fs'); const ncp = require('ncp'); @@ -25,6 +26,20 @@ const versions = require('./source/versions'); // for properties which are not present in the given language const DEFAULT_LANG = 'en'; + +// Add an anchor link. Taken directly from the marked docs +const renderer = new marked.Renderer(); +renderer.heading = function (text, level) { + var escapedText = text.toLowerCase().replace(/[^\w]+/g, '-'); + + return '' + text + '' + + ''; +}; +const markedOptions = { langPrefix: 'language-', renderer: renderer }; + function i18nJSON (lang) { var defaultJSON = require(`./locale/${DEFAULT_LANG}/site.json`); var templateJSON = require(`./locale/${lang}/site.json`); @@ -104,7 +119,7 @@ function buildlocale (locale) { refer: false } })) - .use(markdown({ langPrefix: 'language-' })) + .use(markdown(markedOptions)) .use(prism()) .use(filterStylusPartials()) .use(stylus({ diff --git a/layouts/css/base.styl b/layouts/css/base.styl index d16c1d2c47d83..fe8cad6ceafc0 100644 --- a/layouts/css/base.styl +++ b/layouts/css/base.styl @@ -78,6 +78,7 @@ pre @import 'page-modules/_in-the-news' @import 'page-modules/_download' @import 'page-modules/_scrollToTop' +@import 'page-modules/_anchorLinks' .intro margin-top 140px diff --git a/layouts/css/page-modules/_anchorLinks.styl b/layouts/css/page-modules/_anchorLinks.styl new file mode 100644 index 0000000000000..04f98e5b94332 --- /dev/null +++ b/layouts/css/page-modules/_anchorLinks.styl @@ -0,0 +1,8 @@ +// Anchor links to parts of the page +h1:hover > .anchor:before, +h2:hover > .anchor:before, +h3:hover > .anchor:before, +h4:hover > .anchor:before, +h5:hover > .anchor:before, +h6:hover > .anchor:before + content '#' diff --git a/package.json b/package.json index 116ca2bedaa43..27e2a1cd91f18 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "chokidar": "^1.0.5", "handlebars": "^3.0.0", "map-async": "~0.1.1", + "marked": "^0.3.5", "metalsmith": "^2.0.0", "metalsmith-collections": "^0.7.0", "metalsmith-feed": "0.0.6",