Skip to content

Commit 972d053

Browse files
hikerpigRokt33r
authored andcommitted
fix: array access error when token.map is null, fix #3123
1 parent 7797661 commit 972d053

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

browser/lib/markdown.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ class Markdown {
289289
case 'list_item_open':
290290
case 'paragraph_open':
291291
case 'table_open':
292-
token.attrPush(['data-line', token.map[0]])
292+
if (token.map) {
293+
token.attrPush(['data-line', token.map[0]])
294+
}
293295
}
294296
})
295297
const result = originalRender.call(this.md.renderer, tokens, options, env)

tests/fixtures/markdowns.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ Term 2 with *inline markup*
104104
`
105105
const shortcuts = '<kbd>Ctrl</kbd>\n\n[[Ctrl]]'
106106

107+
const footnote = `
108+
^[hello-world]
109+
hello-world: https://github.com/BoostIO/Boostnote/
110+
`
111+
107112
export default {
108113
basic,
109114
codeblock,
@@ -115,5 +120,6 @@ export default {
115120
subTexts,
116121
supTexts,
117122
deflists,
118-
shortcuts
123+
shortcuts,
124+
footnote
119125
}

tests/lib/markdown-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,8 @@ test('Markdown.render() should render shortcuts correctly', t => {
6868
const rendered = md.render(markdownFixtures.shortcuts)
6969
t.snapshot(rendered)
7070
})
71+
72+
test('Markdown.render() should render footnote correctly', t => {
73+
const rendered = md.render(markdownFixtures.footnote)
74+
t.snapshot(rendered)
75+
})

tests/lib/snapshots/markdown-test.js.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ The actual snapshot is saved in `markdown-test.js.snap`.
44

55
Generated by [AVA](https://ava.li).
66

7+
## Markdown.render() should render footnote correctly
8+
9+
> Snapshot 1
10+
11+
`<p data-line="1"><sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup><br />␊
12+
hello-world: <a href="https://github.com/BoostIO/Boostnote/">https://github.com/BoostIO/Boostnote/</a></p>␊
13+
<hr class="footnotes-sep" />␊
14+
<section class="footnotes">␊
15+
<ol class="footnotes-list">␊
16+
<li id="fn1" class="footnote-item"><p>hello-world <a href="#fnref1" class="footnote-backref">↩︎</a></p>␊
17+
</li>␊
18+
</ol>␊
19+
</section>␊
20+
`
21+
722
## Markdown.render() should render line breaks correctly
823

924
> Snapshot 1
170 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)