-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Facing issues with plugin development #847
Copy link
Copy link
Closed
Description
Hello, I'm currently porting my plugins to char code scan instead of regex (markdown-it-regexp) to improve performance.
While my custom markdown tag works fine, I'm facing an odd issue, other tags that come after it won't render (except for inline code), emphasis tags cause infinite loops that freeze the browser!
Nested markup is working fine btw:
Not sure what I did wrong, I followed the source code of many rules/plugins and I was able to make it work, but couldn't find out what causes this issue. Here is my code anyway:
function spoiler(md) {
const exMark = 0x21 /* ! */
const gtSign = 0x3E /* > */
const ltSign = 0x3C /* < */
md.inline.ruler.after('emphasis', 'spoiler', (state, silent) => {
if (silent) return false
let start = state.pos,
end = state.posMax - 1,
found = false
// Check for >!
if (
state.src.charCodeAt(start) !== gtSign ||
state.src.charCodeAt(start + 1) !== exMark
) {
return false
}
// Find !<
state.pos = end - 1
while (state.pos > start + 1) {
if (
state.src.charCodeAt(state.pos) === exMark &&
state.src.charCodeAt(state.pos + 1) === ltSign
) {
found = true
break
}
state.pos -= 1
}
if (!found) {
state.pos = start
return false
}
state.posMax = state.pos
state.pos = start + 2
let token = state.push('spoiler_open', 'span', 1)
token.attrs = [
['class', 'md-spoiler']
]
token.markup = '>!'
// Parse nested markup
state.md.inline.tokenize(state)
token = state.push('spoiler_close', 'span', -1)
token.markup = '!<'
state.pos += 2
return true
})
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels

