Skip to content

Commit 5a111a2

Browse files
shigmaulivz
authored andcommitted
fix($markdown): fix line highlighting (close: #1364) (#1369)
1 parent 760f90b commit 5a111a2

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

packages/@vuepress/markdown/lib/highlightLines.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,29 @@ module.exports = md => {
99
const [tokens, idx, options] = args
1010
const token = tokens[idx]
1111

12-
const rawInfo = token.info
13-
if (!rawInfo || !RE.test(rawInfo)) {
14-
return fence(...args)
15-
}
12+
if (!token.lineNumbers) {
13+
const rawInfo = token.info
14+
if (!rawInfo || !RE.test(rawInfo)) {
15+
return fence(...args)
16+
}
1617

17-
const langName = rawInfo.replace(RE, '').trim()
18-
// ensure the next plugin get the correct lang.
19-
token.info = langName
18+
const langName = rawInfo.replace(RE, '').trim()
19+
// ensure the next plugin get the correct lang.
20+
token.info = langName
2021

21-
const lineNumbers = RE.exec(rawInfo)[1]
22-
.split(',')
23-
.map(v => v.split('-').map(v => parseInt(v, 10)))
22+
token.lineNumbers = RE.exec(rawInfo)[1]
23+
.split(',')
24+
.map(v => v.split('-').map(v => parseInt(v, 10)))
25+
}
2426

2527
const code = options.highlight
26-
? options.highlight(token.content, langName)
28+
? options.highlight(token.content, token.info)
2729
: token.content
2830

2931
const rawCode = code.replace(wrapperRE, '')
3032
const highlightLinesCode = rawCode.split('\n').map((split, index) => {
3133
const lineNumber = index + 1
32-
const inRange = lineNumbers.some(([start, end]) => {
34+
const inRange = token.lineNumbers.some(([start, end]) => {
3335
if (start && end) {
3436
return lineNumber >= start && lineNumber <= end
3537
}

0 commit comments

Comments
 (0)