| 13 | const plugin = definePlugin({ |
| 14 | name, |
| 15 | transform(transformHooks: ITransformHooks) { |
| 16 | transformHooks.parser.tap((md) => { |
| 17 | md.core.ruler.before('inline', 'checkbox', (state) => { |
| 18 | for (let i = 2; i < state.tokens.length; i += 1) { |
| 19 | const token = state.tokens[i]; |
| 20 | if (token.type === 'inline' && token.content) { |
| 21 | const prevType = state.tokens[i - 1].type; |
| 22 | const prevPrevType = state.tokens[i - 2].type; |
| 23 | // accept heading and list items paragraphs |
| 24 | if ( |
| 25 | prevType === 'heading_open' || |
| 26 | (prevType === 'paragraph_open' && |
| 27 | prevPrevType === 'list_item_open') |
| 28 | ) { |
| 29 | token.content = token.content.replace(/^\[(.)\] /, (m, g) => |
| 30 | images[g] ? `${images[g]} ` : m, |
| 31 | ); |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | return false; |
| 36 | }); |
| 37 | }); |
| 38 | return {}; |
| 39 | }, |
| 40 | }); |
| 41 | |
| 42 | export default plugin; |