Skip to content

Commit 76928e4

Browse files
committed
- add data-line attribute to definition lists and lists
- add tests
1 parent 15b9f8e commit 76928e4

File tree

6 files changed

+155
-19
lines changed

6 files changed

+155
-19
lines changed

browser/lib/markdown-it-deflist.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ module.exports = function definitionListPlugin (md) {
116116

117117
for (;;) {
118118
token = state.push('dd_open', 'dd', 1)
119-
token.map = itemLines = [ nextLine, 0 ]
119+
token.map = itemLines = [ ddLine, 0 ]
120120

121121
pos = contentStart
122122
max = state.eMarks[ddLine]

browser/lib/markdown.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,12 @@ class Markdown {
251251
this.md.renderer.render = (tokens, options, env) => {
252252
tokens.forEach((token) => {
253253
switch (token.type) {
254+
case 'blockquote_open':
255+
case 'dd_open':
256+
case 'dt_open':
254257
case 'heading_open':
258+
case 'list_item_open':
255259
case 'paragraph_open':
256-
case 'blockquote_open':
257260
case 'table_open':
258261
token.attrPush(['data-line', token.map[0]])
259262
}

tests/fixtures/markdowns.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,68 @@ const smartQuotes = 'This is a "QUOTE".'
5050

5151
const breaks = 'This is the first line.\nThis is the second line.'
5252

53+
const abbrevations = `
54+
## abbr
55+
56+
The HTML specification
57+
is maintained by the W3C.
58+
59+
*[HTML]: Hyper Text Markup Language
60+
*[W3C]: World Wide Web Consortium
61+
`
62+
63+
const subTexts = `
64+
## sub
65+
66+
H~2~0
67+
`
68+
69+
const supTexts = `
70+
## sup
71+
72+
29^th^
73+
`
74+
75+
const deflists = `
76+
## definition list
77+
78+
### list 1
79+
80+
Term 1
81+
~ Definition 1
82+
83+
Term 2
84+
~ Definition 2a
85+
~ Definition 2b
86+
87+
Term 3
88+
~
89+
90+
91+
### list 2
92+
93+
Term 1
94+
95+
: Definition 1
96+
97+
Term 2 with *inline markup*
98+
99+
: Definition 2
100+
101+
{ some code, part of Definition 2 }
102+
103+
Third paragraph of definition 2.
104+
`
105+
53106
export default {
54107
basic,
55108
codeblock,
56109
katex,
57110
checkboxes,
58111
smartQuotes,
59-
breaks
112+
breaks,
113+
abbrevations,
114+
subTexts,
115+
supTexts,
116+
deflists
60117
}

tests/lib/markdown-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,23 @@ test('Markdown.render() should render line breaks correctly', t => {
4343
const renderedNonBreaks = newmd.render(markdownFixtures.breaks)
4444
t.snapshot(renderedNonBreaks)
4545
})
46+
47+
test('Markdown.render() should renders abbrevations correctly', t => {
48+
const rendered = md.render(markdownFixtures.abbrevations)
49+
t.snapshot(rendered)
50+
})
51+
52+
test('Markdown.render() should renders sub correctly', t => {
53+
const rendered = md.render(markdownFixtures.subTexts)
54+
t.snapshot(rendered)
55+
})
56+
57+
test('Markdown.render() should renders sup correctly', t => {
58+
const rendered = md.render(markdownFixtures.supTexts)
59+
t.snapshot(rendered)
60+
})
61+
62+
test('Markdown.render() should renders definition lists correctly', t => {
63+
const rendered = md.render(markdownFixtures.deflists)
64+
t.snapshot(rendered)
65+
})

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

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@ Generated by [AVA](https://ava.li).
2525
`<span class="katex-display"><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>c</mi><mo>=</mo><mi>p</mi><mi>m</mi><mi>s</mi><mi>q</mi><mi>r</mi><mi>t</mi><mrow><msup><mi>a</mi><mn>2</mn></msup><mo>+</mo><msup><mi>b</mi><mn>2</mn></msup></mrow></mrow><annotation encoding="application/x-tex">c = pmsqrt{a^2 + b^2}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.8641079999999999em;"></span><span class="strut bottom" style="height:1.0585479999999998em;vertical-align:-0.19444em;"></span><span class="base"><span class="mord mathit">c</span><span class="mord rule" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mord rule" style="margin-right:0.2777777777777778em;"></span><span class="mord mathit">p</span><span class="mord mathit">m</span><span class="mord mathit">s</span><span class="mord mathit" style="margin-right:0.03588em;">q</span><span class="mord mathit" style="margin-right:0.02778em;">r</span><span class="mord mathit">t</span><span class="mord"><span class="mord"><span class="mord mathit">a</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mord rule" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mord rule" style="margin-right:0.2222222222222222em;"></span><span class="mord"><span class="mord mathit">b</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span></span></span></span></span></span>␊
2626
`
2727

28+
## Markdown.render() should renders abbrevations correctly
29+
30+
> Snapshot 1
31+
32+
`<h2 data-line="1" id="abbr">abbr</h2>␊
33+
<p data-line="3">The <abbr title="Hyper Text Markup Language">HTML</abbr> specification<br />␊
34+
is maintained by the <abbr title="World Wide Web Consortium">W3C</abbr>.</p>␊
35+
`
36+
2837
## Markdown.render() should renders checkboxes
2938

3039
> Snapshot 1
3140
3241
`<ul>␊
33-
<li class="taskListItem"><input type="checkbox" id="checkbox-2" /> Unchecked</li>␊
34-
<li class="taskListItem"><input type="checkbox" checked id="checkbox-3" /> Checked</li>␊
42+
<li class="taskListItem" data-line="1"><input type="checkbox" id="checkbox-2" /> Unchecked</li>␊
43+
<li class="taskListItem" data-line="2"><input type="checkbox" checked id="checkbox-3" /> Checked</li>␊
3544
</ul>␊
3645
`
3746

@@ -43,6 +52,37 @@ Generated by [AVA](https://ava.li).
4352
</code></pre>␊
4453
`
4554

55+
## Markdown.render() should renders definition lists correctly
56+
57+
> Snapshot 1
58+
59+
`<h2 data-line="1" id="definition-list">definition list</h2>␊
60+
<h3 data-line="3" id="list-1">list 1</h3>␊
61+
<dl>␊
62+
<dt data-line="5">Term 1</dt>␊
63+
<dd data-line="6">Definition 1</dd>␊
64+
<dt data-line="8">Term 2</dt>␊
65+
<dd data-line="9">Definition 2a</dd>␊
66+
<dd data-line="10">Definition 2b</dd>␊
67+
</dl>␊
68+
<p data-line="12">Term 3<br />␊
69+
~</p>␊
70+
<h3 data-line="16" id="list-2">list 2</h3>␊
71+
<dl>␊
72+
<dt data-line="18">Term 1</dt>␊
73+
<dd data-line="20">␊
74+
<p data-line="20">Definition 1</p>␊
75+
</dd>␊
76+
<dt data-line="22">Term 2 with <em>inline markup</em></dt>␊
77+
<dd data-line="24">␊
78+
<p data-line="24">Definition 2</p>␊
79+
<pre><code> { some code, part of Definition 2 }␊
80+
</code></pre>␊
81+
<p data-line="28">Third paragraph of definition 2.</p>␊
82+
</dd>␊
83+
</dl>␊
84+
`
85+
4686
## Markdown.render() should renders markdown correctly
4787

4888
> Snapshot 1
@@ -52,31 +92,47 @@ Generated by [AVA](https://ava.li).
5292
<iframe width="560" height="315" src="https://www.youtube.com/embed/L0qNPLsvmyM" frameborder="0" allowfullscreen></iframe>␊
5393
<h2 data-line="6" id="Docs-%F0%9F%93%9D">Docs 📝</h2>␊
5494
<ul>␊
55-
<li><a href="https://hackernoon.com/boostnote-boost-your-happiness-productivity-and-creativity-315034efeebe">Boostnote | Boost your happiness, productivity and creativity.</a></li>␊
56-
<li><a href="https://github.com/BoostIO/Boostnote/wiki/Cloud-Syncing-and-Backup">Cloud Syncing &amp; Backups</a></li>␊
57-
<li><a href="https://github.com/BoostIO/Boostnote/wiki/Sync-Data-Across-Desktop-and-Mobile-apps">How to sync your data across Desktop and Mobile apps</a></li>␊
58-
<li><a href="https://github.com/BoostIO/Boostnote/wiki/Evernote">Convert data from <strong>Evernote</strong> to Boostnote.</a></li>␊
59-
<li><a href="https://github.com/BoostIO/Boostnote/wiki/Keyboard-Shortcuts">Keyboard Shortcuts</a></li>␊
60-
<li><a href="https://github.com/BoostIO/Boostnote/wiki/Keymaps-in-Editor-mode">Keymaps in Editor mode</a></li>␊
61-
<li><a href="https://github.com/BoostIO/Boostnote/wiki/Syntax-Highlighting">How to set syntax highlight in Snippet note</a></li>␊
95+
<li data-line="7"><a href="https://hackernoon.com/boostnote-boost-your-happiness-productivity-and-creativity-315034efeebe">Boostnote | Boost your happiness, productivity and creativity.</a></li>␊
96+
<li data-line="8"><a href="https://github.com/BoostIO/Boostnote/wiki/Cloud-Syncing-and-Backup">Cloud Syncing &amp; Backups</a></li>␊
97+
<li data-line="9"><a href="https://github.com/BoostIO/Boostnote/wiki/Sync-Data-Across-Desktop-and-Mobile-apps">How to sync your data across Desktop and Mobile apps</a></li>␊
98+
<li data-line="10"><a href="https://github.com/BoostIO/Boostnote/wiki/Evernote">Convert data from <strong>Evernote</strong> to Boostnote.</a></li>␊
99+
<li data-line="11"><a href="https://github.com/BoostIO/Boostnote/wiki/Keyboard-Shortcuts">Keyboard Shortcuts</a></li>␊
100+
<li data-line="12"><a href="https://github.com/BoostIO/Boostnote/wiki/Keymaps-in-Editor-mode">Keymaps in Editor mode</a></li>␊
101+
<li data-line="13"><a href="https://github.com/BoostIO/Boostnote/wiki/Syntax-Highlighting">How to set syntax highlight in Snippet note</a></li>␊
62102
</ul>␊
63103
<hr />␊
64104
<h2 data-line="17" id="Article-Archive-%F0%9F%93%9A">Article Archive 📚</h2>␊
65105
<ul>␊
66-
<li><a href="http://bit.ly/2mOJPu7">Reddit English</a></li>␊
67-
<li><a href="https://www.reddit.com/r/boostnote_es/">Reddit Spanish</a></li>␊
68-
<li><a href="https://www.reddit.com/r/boostnote_cn/">Reddit Chinese</a></li>␊
69-
<li><a href="https://www.reddit.com/r/boostnote_jp/">Reddit Japanese</a></li>␊
106+
<li data-line="18"><a href="http://bit.ly/2mOJPu7">Reddit English</a></li>␊
107+
<li data-line="19"><a href="https://www.reddit.com/r/boostnote_es/">Reddit Spanish</a></li>␊
108+
<li data-line="20"><a href="https://www.reddit.com/r/boostnote_cn/">Reddit Chinese</a></li>␊
109+
<li data-line="21"><a href="https://www.reddit.com/r/boostnote_jp/">Reddit Japanese</a></li>␊
70110
</ul>␊
71111
<hr />␊
72112
<h2 data-line="25" id="Community-%F0%9F%8D%BB">Community 🍻</h2>␊
73113
<ul>␊
74-
<li><a href="http://bit.ly/2AWWzkD">GitHub</a></li>␊
75-
<li><a href="http://bit.ly/2z8BUJZ">Twitter</a></li>␊
76-
<li><a href="http://bit.ly/2jcca8t">Facebook Group</a></li>␊
114+
<li data-line="26"><a href="http://bit.ly/2AWWzkD">GitHub</a></li>␊
115+
<li data-line="27"><a href="http://bit.ly/2z8BUJZ">Twitter</a></li>␊
116+
<li data-line="28"><a href="http://bit.ly/2jcca8t">Facebook Group</a></li>␊
77117
</ul>␊
78118
`
79119

120+
## Markdown.render() should renders sub correctly
121+
122+
> Snapshot 1
123+
124+
`<h2 data-line="1" id="sub">sub</h2>␊
125+
<p data-line="3">H<sub>2</sub>0</p>␊
126+
`
127+
128+
## Markdown.render() should renders sup correctly
129+
130+
> Snapshot 1
131+
132+
`<h2 data-line="1" id="sup">sup</h2>␊
133+
<p data-line="3">29<sup>th</sup></p>␊
134+
`
135+
80136
## Markdown.render() should text with quotes correctly
81137

82138
> Snapshot 1
541 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)