mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Fixed duplicate TOC Title jump error
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
import toc from 'markdown-toc'
|
import toc from 'markdown-toc'
|
||||||
import diacritics from 'diacritics-map'
|
import diacritics from 'diacritics-map'
|
||||||
import stripColor from 'strip-color'
|
import stripColor from 'strip-color'
|
||||||
|
import mdlink from 'markdown-link'
|
||||||
|
|
||||||
const EOL = require('os').EOL
|
const EOL = require('os').EOL
|
||||||
|
|
||||||
@@ -42,6 +43,12 @@ function caseSensitiveSlugify (str) {
|
|||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function linkify (tok, text, slug, opts) {
|
||||||
|
var uniqeID = opts.num === 0 ? '' : '-' + opts.num
|
||||||
|
tok.content = mdlink(text, '#' + slug + uniqeID)
|
||||||
|
return tok
|
||||||
|
}
|
||||||
|
|
||||||
const TOC_MARKER_START = '<!-- toc -->'
|
const TOC_MARKER_START = '<!-- toc -->'
|
||||||
const TOC_MARKER_END = '<!-- tocstop -->'
|
const TOC_MARKER_END = '<!-- tocstop -->'
|
||||||
|
|
||||||
@@ -84,7 +91,7 @@ export function generateInEditor (editor) {
|
|||||||
* @returns generatedTOC String containing generated TOC
|
* @returns generatedTOC String containing generated TOC
|
||||||
*/
|
*/
|
||||||
export function generate (markdownText) {
|
export function generate (markdownText) {
|
||||||
const generatedToc = toc(markdownText, {slugify: caseSensitiveSlugify})
|
const generatedToc = toc(markdownText, {slugify: caseSensitiveSlugify, linkify: linkify})
|
||||||
return TOC_MARKER_START + EOL + EOL + generatedToc.content + EOL + EOL + TOC_MARKER_END
|
return TOC_MARKER_START + EOL + EOL + generatedToc.content + EOL + EOL + TOC_MARKER_END
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import _ from 'lodash'
|
|||||||
import ConfigManager from 'browser/main/lib/ConfigManager'
|
import ConfigManager from 'browser/main/lib/ConfigManager'
|
||||||
import katex from 'katex'
|
import katex from 'katex'
|
||||||
import { lastFindInArray } from './utils'
|
import { lastFindInArray } from './utils'
|
||||||
import ee from 'browser/main/lib/eventEmitter'
|
import anchor from '@enyaxu/markdown-it-anchor'
|
||||||
|
|
||||||
function createGutter (str, firstLineNumber) {
|
function createGutter (str, firstLineNumber) {
|
||||||
if (Number.isNaN(firstLineNumber)) firstLineNumber = 1
|
if (Number.isNaN(firstLineNumber)) firstLineNumber = 1
|
||||||
@@ -118,12 +118,13 @@ class Markdown {
|
|||||||
this.md.use(require('markdown-it-imsize'))
|
this.md.use(require('markdown-it-imsize'))
|
||||||
this.md.use(require('markdown-it-footnote'))
|
this.md.use(require('markdown-it-footnote'))
|
||||||
this.md.use(require('markdown-it-multimd-table'))
|
this.md.use(require('markdown-it-multimd-table'))
|
||||||
this.md.use(require('markdown-it-named-headers'), {
|
this.md.use(anchor, {
|
||||||
slugify: (header) => {
|
slugify: (title) => {
|
||||||
return encodeURI(header.trim()
|
var slug = encodeURI(title.trim()
|
||||||
.replace(/[\]\[\!\"\#\$\%\&\'\(\)\*\+\,\.\/\:\;\<\=\>\?\@\\\^\_\{\|\}\~]/g, '')
|
.replace(/[\]\[\!\"\#\$\%\&\'\(\)\*\+\,\.\/\:\;\<\=\>\?\@\\\^\_\{\|\}\~]/g, '')
|
||||||
.replace(/\s+/g, '-'))
|
.replace(/\s+/g, '-'))
|
||||||
.replace(/\-+$/, '')
|
.replace(/\-+$/, '')
|
||||||
|
return slug
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.md.use(require('markdown-it-kbd'))
|
this.md.use(require('markdown-it-kbd'))
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://boostnote.io",
|
"homepage": "https://boostnote.io",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@enyaxu/markdown-it-anchor": "^5.0.2",
|
||||||
"@rokt33r/markdown-it-math": "^4.0.1",
|
"@rokt33r/markdown-it-math": "^4.0.1",
|
||||||
"@rokt33r/season": "^5.3.0",
|
"@rokt33r/season": "^5.3.0",
|
||||||
"@susisu/mte-kernel": "^2.0.0",
|
"@susisu/mte-kernel": "^2.0.0",
|
||||||
@@ -80,7 +81,6 @@
|
|||||||
"markdown-it-imsize": "^2.0.1",
|
"markdown-it-imsize": "^2.0.1",
|
||||||
"markdown-it-kbd": "^1.1.1",
|
"markdown-it-kbd": "^1.1.1",
|
||||||
"markdown-it-multimd-table": "^2.0.1",
|
"markdown-it-multimd-table": "^2.0.1",
|
||||||
"markdown-it-named-headers": "^0.0.4",
|
|
||||||
"markdown-it-plantuml": "^1.1.0",
|
"markdown-it-plantuml": "^1.1.0",
|
||||||
"markdown-it-smartarrows": "^1.0.1",
|
"markdown-it-smartarrows": "^1.0.1",
|
||||||
"markdown-it-sub": "^1.0.0",
|
"markdown-it-sub": "^1.0.0",
|
||||||
@@ -104,10 +104,10 @@
|
|||||||
"sander": "^0.5.1",
|
"sander": "^0.5.1",
|
||||||
"sanitize-html": "^1.18.2",
|
"sanitize-html": "^1.18.2",
|
||||||
"striptags": "^2.2.1",
|
"striptags": "^2.2.1",
|
||||||
|
"turndown": "^4.0.2",
|
||||||
|
"turndown-plugin-gfm": "^1.0.2",
|
||||||
"unique-slug": "2.0.0",
|
"unique-slug": "2.0.0",
|
||||||
"uuid": "^3.2.1",
|
"uuid": "^3.2.1"
|
||||||
"turndown":"^4.0.2",
|
|
||||||
"turndown-plugin-gfm":"^1.0.2"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ava": "^0.25.0",
|
"ava": "^0.25.0",
|
||||||
|
|||||||
15
yarn.lock
15
yarn.lock
@@ -58,6 +58,11 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
arrify "^1.0.1"
|
arrify "^1.0.1"
|
||||||
|
|
||||||
|
"@enyaxu/markdown-it-anchor@^5.0.2":
|
||||||
|
version "5.0.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/@enyaxu/markdown-it-anchor/-/markdown-it-anchor-5.0.2.tgz#d173f7b60b492aabc17dfba864c4d071f5595f72"
|
||||||
|
integrity sha512-HBQ+by3IFHh2i5nw8fzn9qrdA+6uwzre68EzHpBX/WrwgnKrfvckPzdi7MphKp2C617edfpeibucslHDNPYkvQ==
|
||||||
|
|
||||||
"@ladjs/time-require@^0.1.4":
|
"@ladjs/time-require@^0.1.4":
|
||||||
version "0.1.4"
|
version "0.1.4"
|
||||||
resolved "https://registry.yarnpkg.com/@ladjs/time-require/-/time-require-0.1.4.tgz#5c615d75fd647ddd5de9cf6922649558856b21a1"
|
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:
|
|||||||
dependencies:
|
dependencies:
|
||||||
markdown-it "^5.0.3"
|
markdown-it "^5.0.3"
|
||||||
|
|
||||||
markdown-it-named-headers@^0.0.4:
|
|
||||||
version "0.0.4"
|
|
||||||
resolved "https://registry.yarnpkg.com/markdown-it-named-headers/-/markdown-it-named-headers-0.0.4.tgz#82efc28324240a6b1e77b9aae501771d5f351c1f"
|
|
||||||
dependencies:
|
|
||||||
string "^3.0.1"
|
|
||||||
|
|
||||||
markdown-it-plantuml@^1.1.0:
|
markdown-it-plantuml@^1.1.0:
|
||||||
version "1.1.0"
|
version "1.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/markdown-it-plantuml/-/markdown-it-plantuml-1.1.0.tgz#9ab8bfa09a02d80845e16e60f87a488edb50fdde"
|
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:
|
|||||||
is-fullwidth-code-point "^2.0.0"
|
is-fullwidth-code-point "^2.0.0"
|
||||||
strip-ansi "^4.0.0"
|
strip-ansi "^4.0.0"
|
||||||
|
|
||||||
string@^3.0.1:
|
|
||||||
version "3.3.3"
|
|
||||||
resolved "https://registry.yarnpkg.com/string/-/string-3.3.3.tgz#5ea211cd92d228e184294990a6cc97b366a77cb0"
|
|
||||||
|
|
||||||
string_decoder@^0.10.25, string_decoder@~0.10.x:
|
string_decoder@^0.10.25, string_decoder@~0.10.x:
|
||||||
version "0.10.31"
|
version "0.10.31"
|
||||||
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"
|
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"
|
||||||
|
|||||||
Reference in New Issue
Block a user