feat: markdown anchors

This commit is contained in:
Nicolas Giard 2018-09-17 00:36:44 -04:00
parent d393a95495
commit d52f213012
4 changed files with 41 additions and 0 deletions

View File

@ -3,6 +3,26 @@
.contents { .contents {
color: mc('grey', '800'); color: mc('grey', '800');
h1, h2, h3, h4, h5, h6 {
position: relative;
&:hover {
.toc-anchor {
display: block;
}
}
.toc-anchor {
display: none;
position: absolute;
right: 1rem;
bottom: .5rem;
font-size: 1.25rem;
text-decoration: none;
color: mc('grey', '500');
}
}
h1 { h1 {
padding-left: 24px; padding-left: 24px;
color: mc('blue', '800'); color: mc('blue', '800');

View File

@ -147,6 +147,7 @@
"semver": "5.5.1", "semver": "5.5.1",
"serve-favicon": "2.5.0", "serve-favicon": "2.5.0",
"sqlite3": "4.0.2", "sqlite3": "4.0.2",
"uslug": "1.0.4",
"uuid": "3.3.2", "uuid": "3.3.2",
"validator": "10.7.1", "validator": "10.7.1",
"validator-as-promised": "1.0.2", "validator-as-promised": "1.0.2",

View File

@ -1,5 +1,7 @@
const md = require('markdown-it') const md = require('markdown-it')
const mdAnchor = require('markdown-it-anchor')
const _ = require('lodash') const _ = require('lodash')
const uslug = require('uslug')
const quoteStyles = { const quoteStyles = {
Chinese: '””‘’', Chinese: '””‘’',
@ -29,6 +31,14 @@ module.exports = {
} }
}) })
mkdown.use(mdAnchor, {
slugify: s => uslug(s),
permalink: true,
permalinkClass: 'toc-anchor',
permalinkSymbol: '¶',
permalinkBefore: true
})
for (let child of this.children) { for (let child of this.children) {
const renderer = require(`../${_.kebabCase(child.key)}/renderer.js`) const renderer = require(`../${_.kebabCase(child.key)}/renderer.js`)
renderer.init(mkdown, child.config) renderer.init(mkdown, child.config)

View File

@ -12085,6 +12085,10 @@ universalify@^0.1.0:
version "0.1.1" version "0.1.1"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7" resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"
"unorm@>= 1.0.0":
version "1.4.1"
resolved "https://registry.yarnpkg.com/unorm/-/unorm-1.4.1.tgz#364200d5f13646ca8bcd44490271335614792300"
unpipe@1.0.0, unpipe@~1.0.0: unpipe@1.0.0, unpipe@~1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
@ -12172,6 +12176,12 @@ use@^3.1.0:
dependencies: dependencies:
kind-of "^6.0.2" kind-of "^6.0.2"
uslug@1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/uslug/-/uslug-1.0.4.tgz#b9a22f0914e0a86140633dacc302e5f4fa450677"
dependencies:
unorm ">= 1.0.0"
util-deprecate@~1.0.1: util-deprecate@~1.0.1:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"