Skip to content

Commit e70006a

Browse files
Merge pull request #77 from akinomyoga/marked-migration
kunai-config: Handle Marked v1.0.0 tokens
2 parents 56ab5cd + d5d194f commit e70006a

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
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.get('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
],

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "crsearch",
3-
"version": "3.0.23",
3+
"version": "3.0.24",
44
"description": "cpprefjp / boostjp searcher",
55
"main": "dist/js/crsearch.js",
66
"module": "js/crsearch.js",

0 commit comments

Comments
 (0)