File tree Expand file tree Collapse file tree 4 files changed +22
-19
lines changed Expand file tree Collapse file tree 4 files changed +22
-19
lines changed Original file line number Diff line number Diff line change 5
5
import toc from 'markdown-toc'
6
6
import diacritics from 'diacritics-map'
7
7
import stripColor from 'strip-color'
8
+ import mdlink from 'markdown-link'
8
9
9
10
const EOL = require ( 'os' ) . EOL
10
11
@@ -42,6 +43,12 @@ function caseSensitiveSlugify (str) {
42
43
return str
43
44
}
44
45
46
+ function linkify ( tok , text , slug , opts ) {
47
+ var uniqeID = opts . num === 0 ? '' : '-' + opts . num
48
+ tok . content = mdlink ( text , '#' + slug + uniqeID )
49
+ return tok
50
+ }
51
+
45
52
const TOC_MARKER_START = '<!-- toc -->'
46
53
const TOC_MARKER_END = '<!-- tocstop -->'
47
54
@@ -84,7 +91,7 @@ export function generateInEditor (editor) {
84
91
* @returns generatedTOC String containing generated TOC
85
92
*/
86
93
export function generate ( markdownText ) {
87
- const generatedToc = toc ( markdownText , { slugify : caseSensitiveSlugify } )
94
+ const generatedToc = toc ( markdownText , { slugify : caseSensitiveSlugify , linkify : linkify } )
88
95
return TOC_MARKER_START + EOL + EOL + generatedToc . content + EOL + EOL + TOC_MARKER_END
89
96
}
90
97
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import _ from 'lodash'
7
7
import ConfigManager from 'browser/main/lib/ConfigManager'
8
8
import katex from 'katex'
9
9
import { lastFindInArray } from './utils'
10
- import ee from 'browser/main/lib/eventEmitter '
10
+ import anchor from '@enyaxu/markdown-it-anchor '
11
11
12
12
function createGutter ( str , firstLineNumber ) {
13
13
if ( Number . isNaN ( firstLineNumber ) ) firstLineNumber = 1
@@ -118,12 +118,13 @@ class Markdown {
118
118
this . md . use ( require ( 'markdown-it-imsize' ) )
119
119
this . md . use ( require ( 'markdown-it-footnote' ) )
120
120
this . md . use ( require ( 'markdown-it-multimd-table' ) )
121
- this . md . use ( require ( 'markdown-it-named-headers' ) , {
122
- slugify : ( header ) => {
123
- return encodeURI ( header . trim ( )
121
+ this . md . use ( anchor , {
122
+ slugify : ( title ) => {
123
+ var slug = encodeURI ( title . trim ( )
124
124
. replace ( / [ \] \[ \! \" \# \$ \% \& \' \( \) \* \+ \, \. \/ \: \; \< \= \> \? \@ \\ \^ \_ \{ \| \} \~ ] / g, '' )
125
125
. replace ( / \s + / g, '-' ) )
126
126
. replace ( / \- + $ / , '' )
127
+ return slug
127
128
}
128
129
} )
129
130
this . md . use ( require ( 'markdown-it-kbd' ) )
Original file line number Diff line number Diff line change 47
47
},
48
48
"homepage" : " https://boostnote.io" ,
49
49
"dependencies" : {
50
+ "@enyaxu/markdown-it-anchor" : " ^5.0.2" ,
50
51
"@rokt33r/markdown-it-math" : " ^4.0.1" ,
51
52
"@rokt33r/season" : " ^5.3.0" ,
52
53
"@susisu/mte-kernel" : " ^2.0.0" ,
80
81
"markdown-it-imsize" : " ^2.0.1" ,
81
82
"markdown-it-kbd" : " ^1.1.1" ,
82
83
"markdown-it-multimd-table" : " ^2.0.1" ,
83
- "markdown-it-named-headers" : " ^0.0.4" ,
84
84
"markdown-it-plantuml" : " ^1.1.0" ,
85
85
"markdown-it-smartarrows" : " ^1.0.1" ,
86
86
"markdown-it-sub" : " ^1.0.0" ,
104
104
"sander" : " ^0.5.1" ,
105
105
"sanitize-html" : " ^1.18.2" ,
106
106
"striptags" : " ^2.2.1" ,
107
+ "turndown" : " ^4.0.2" ,
108
+ "turndown-plugin-gfm" : " ^1.0.2" ,
107
109
"unique-slug" : " 2.0.0" ,
108
- "uuid" : " ^3.2.1" ,
109
- "turndown" :" ^4.0.2" ,
110
- "turndown-plugin-gfm" :" ^1.0.2"
110
+ "uuid" : " ^3.2.1"
111
111
},
112
112
"devDependencies" : {
113
113
"ava" : " ^0.25.0" ,
Original file line number Diff line number Diff line change 58
58
dependencies :
59
59
arrify "^1.0.1"
60
60
61
+ " @enyaxu/markdown-it-anchor@^5.0.2 " :
62
+ version "5.0.2"
63
+ resolved "https://registry.yarnpkg.com/@enyaxu/markdown-it-anchor/-/markdown-it-anchor-5.0.2.tgz#d173f7b60b492aabc17dfba864c4d071f5595f72"
64
+ integrity sha512-HBQ+by3IFHh2i5nw8fzn9qrdA+6uwzre68EzHpBX/WrwgnKrfvckPzdi7MphKp2C617edfpeibucslHDNPYkvQ==
65
+
61
66
" @ladjs/time-require@^0.1.4 " :
62
67
version "0.1.4"
63
68
resolved "https://registry.yarnpkg.com/@ladjs/time-require/-/time-require-0.1.4.tgz#5c615d75fd647ddd5de9cf6922649558856b21a1"
@@ -5878,12 +5883,6 @@ markdown-it-multimd-table@^2.0.1:
5878
5883
dependencies :
5879
5884
markdown-it "^5.0.3"
5880
5885
5881
- markdown-it-named-headers@^0.0.4 :
5882
- version "0.0.4"
5883
- resolved "https://registry.yarnpkg.com/markdown-it-named-headers/-/markdown-it-named-headers-0.0.4.tgz#82efc28324240a6b1e77b9aae501771d5f351c1f"
5884
- dependencies :
5885
- string "^3.0.1"
5886
-
5887
5886
markdown-it-plantuml@^1.1.0 :
5888
5887
version "1.1.0"
5889
5888
resolved "https://registry.yarnpkg.com/markdown-it-plantuml/-/markdown-it-plantuml-1.1.0.tgz#9ab8bfa09a02d80845e16e60f87a488edb50fdde"
@@ -8454,10 +8453,6 @@ string-width@^1.0.1, string-width@^1.0.2:
8454
8453
is-fullwidth-code-point "^2.0.0"
8455
8454
strip-ansi "^4.0.0"
8456
8455
8457
- string@^3.0.1 :
8458
- version "3.3.3"
8459
- resolved "https://registry.yarnpkg.com/string/-/string-3.3.3.tgz#5ea211cd92d228e184294990a6cc97b366a77cb0"
8460
-
8461
8456
string_decoder@^0.10.25, string_decoder@~0.10.x :
8462
8457
version "0.10.31"
8463
8458
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"
You can’t perform that action at this time.
0 commit comments