Skip to content

Commit

Permalink
Merge pull request #77 from akinomyoga/marked-migration
Browse files Browse the repository at this point in the history
kunai-config: Handle Marked v1.0.0 tokens
  • Loading branch information
faithandbrave authored Jan 14, 2025
2 parents 56ab5cd + d5d194f commit e70006a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
30 changes: 28 additions & 2 deletions js/crsearch/kunai-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ class ArticleProcessor {
this._zoneProc = new Map([
[
Prop.toplevel_category, {
/* Token handlers for Marked >= v1.0.0 */
'list': list => {
for (const item of list.get('items')) {
if (item.type !== 'list_item') continue

let buf = ''
for (const token of item.tokens) {
if (token.type === 'text')
buf += token.text
}

const m = buf.match(/^([^[]+)\[([^\]]+)\]$/)
if (!m) {
throw new Error(`[BUG] unhandled format ${buf}`)
}

this._categories.set(
m[2],
new Priority(
this._currentIndex++, m[1]
)
)
}
},

/* Token handlers for Marked < v1.0.0 */
'list_item_start': () => {
this._single_bufs.push('')
},
Expand All @@ -67,8 +93,8 @@ class ArticleProcessor {
)
},
'text': token => {
// console.log(token)
this._single_bufs[this._single_bufs.length - 1] += token.get('text').trim()
if (this._single_bufs.length > 0)
this._single_bufs[this._single_bufs.length - 1] += token.get('text').trim()
},
}
],
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crsearch",
"version": "3.0.23",
"version": "3.0.24",
"description": "cpprefjp / boostjp searcher",
"main": "dist/js/crsearch.js",
"module": "js/crsearch.js",
Expand Down

0 comments on commit e70006a

Please sign in to comment.