Skip to content

Commit ff91f01

Browse files
committed
kunai-config: Handle Marked v1.0.0 tokens
cpprefjp/kunai#145 (comment)
1 parent 56ab5cd commit ff91f01

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

js/crsearch/kunai-config.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,32 @@ class ArticleProcessor {
4747
this._zoneProc = new Map([
4848
[
4949
Prop.toplevel_category, {
50+
/* Token handlers for Marked >= v1.0.0 */
51+
'list': list => {
52+
for (const item of list.items) {
53+
if (item.type != 'list_item') continue
54+
55+
let buf = ''
56+
for (const token of item.tokens) {
57+
if (token.type == 'text')
58+
buf += token.text
59+
}
60+
61+
const m = buf.match(/^([^[]+)\[([^\]]+)\]$/)
62+
if (!m) {
63+
throw new Error(`[BUG] unhandled format ${buf}`)
64+
}
65+
66+
this._categories.set(
67+
m[2],
68+
new Priority(
69+
this._currentIndex++, m[1]
70+
)
71+
)
72+
}
73+
},
74+
75+
/* Token handlers for Marked < v1.0.0 */
5076
'list_item_start': () => {
5177
this._single_bufs.push('')
5278
},
@@ -67,8 +93,8 @@ class ArticleProcessor {
6793
)
6894
},
6995
'text': token => {
70-
// console.log(token)
71-
this._single_bufs[this._single_bufs.length - 1] += token.get('text').trim()
96+
if (this._single_bufs.length > 0)
97+
this._single_bufs[this._single_bufs.length - 1] += token.get('text').trim()
7298
},
7399
}
74100
],

0 commit comments

Comments
 (0)