// since the markdown.it interface is a bit on the verbose side // we can keep some general patterns here export default null; // creates a rule suitable for inline parsing and replacement // // example: // const rule = inlineRegexRule(md, { // start: '#', // matcher: /^#([\w-:]{1,101})/i, // emitter: emitter // }); export function inlineRegexRule(md, options) { const start = options.start.charCodeAt(0); const maxLength = (options.maxLength || 500) + 1; return function(state) { const pos = state.pos; if (state.src.charCodeAt(pos) !== start) { return false; } // test prev if (pos > 0) { let prev = state.src.charCodeAt(pos-1); if (!md.utils.isSpace(prev) && !md.utils.isPunctChar(String.fromCharCode(prev))) { return false; } } // skip if in a link if (options.skipInLink && state.tokens) { let last = state.tokens[state.tokens.length-1]; if (last) { if (last.type === 'link_open') { return false; } if (last.type === 'html_inline' && last.content.substr(0,2) === "= 0; i--) { token = tokens[i]; if (token.type === 'link_open' || token.type === 'link_close') { if (token.info === 'auto') { autolinkLevel -= token.nesting; } } if (token.type === 'text' && autolinkLevel === 0) { let split; if(split = callback(token.content, state)) { // replace current node blockTokens[j].children = tokens = state.md.utils.arrayReplaceAt( tokens, i, split ); } } } } }