Skip to content

Commit d52f213

Browse files
committed
feat: markdown anchors
1 parent d393a95 commit d52f213

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

client/themes/default/scss/app.scss

+20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
.contents {
44
color: mc('grey', '800');
55

6+
h1, h2, h3, h4, h5, h6 {
7+
position: relative;
8+
9+
&:hover {
10+
.toc-anchor {
11+
display: block;
12+
}
13+
}
14+
15+
.toc-anchor {
16+
display: none;
17+
position: absolute;
18+
right: 1rem;
19+
bottom: .5rem;
20+
font-size: 1.25rem;
21+
text-decoration: none;
22+
color: mc('grey', '500');
23+
}
24+
}
25+
626
h1 {
727
padding-left: 24px;
828
color: mc('blue', '800');

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
"semver": "5.5.1",
148148
"serve-favicon": "2.5.0",
149149
"sqlite3": "4.0.2",
150+
"uslug": "1.0.4",
150151
"uuid": "3.3.2",
151152
"validator": "10.7.1",
152153
"validator-as-promised": "1.0.2",

server/modules/rendering/markdown-core/renderer.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const md = require('markdown-it')
2+
const mdAnchor = require('markdown-it-anchor')
23
const _ = require('lodash')
4+
const uslug = require('uslug')
35

46
const quoteStyles = {
57
Chinese: '””‘’',
@@ -29,6 +31,14 @@ module.exports = {
2931
}
3032
})
3133

34+
mkdown.use(mdAnchor, {
35+
slugify: s => uslug(s),
36+
permalink: true,
37+
permalinkClass: 'toc-anchor',
38+
permalinkSymbol: '¶',
39+
permalinkBefore: true
40+
})
41+
3242
for (let child of this.children) {
3343
const renderer = require(`../${_.kebabCase(child.key)}/renderer.js`)
3444
renderer.init(mkdown, child.config)

yarn.lock

+10
Original file line numberDiff line numberDiff line change
@@ -12085,6 +12085,10 @@ universalify@^0.1.0:
1208512085
version "0.1.1"
1208612086
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"
1208712087

12088+
"unorm@>= 1.0.0":
12089+
version "1.4.1"
12090+
resolved "https://registry.yarnpkg.com/unorm/-/unorm-1.4.1.tgz#364200d5f13646ca8bcd44490271335614792300"
12091+
1208812092
[email protected], unpipe@~1.0.0:
1208912093
version "1.0.0"
1209012094
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
@@ -12172,6 +12176,12 @@ use@^3.1.0:
1217212176
dependencies:
1217312177
kind-of "^6.0.2"
1217412178

12179+
12180+
version "1.0.4"
12181+
resolved "https://registry.yarnpkg.com/uslug/-/uslug-1.0.4.tgz#b9a22f0914e0a86140633dacc302e5f4fa450677"
12182+
dependencies:
12183+
unorm ">= 1.0.0"
12184+
1217512185
util-deprecate@~1.0.1:
1217612186
version "1.0.2"
1217712187
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"

0 commit comments

Comments
 (0)