From 91871d2cedc7cdb3f49747d4ca6a046a94df845a Mon Sep 17 00:00:00 2001 From: cdruan <80615570+cdruan@users.noreply.github.com> Date: Fri, 10 Oct 2025 05:31:11 -0700 Subject: [PATCH] Markdown: Fix missing inline support and macrocall args parsing error (#9295) * Rewrote tw_macrocallinline() parser so macrocall args containing ">" will be parsed properly. * Use $tw.log.MARKDOWN flag to print debug messages. * Fix markdown parser to respect parseAsInline option. (#8917) --- .../markdown/markdown-it-tiddlywiki.js | 21 ++++++++----------- plugins/tiddlywiki/markdown/styles.tid | 3 +++ plugins/tiddlywiki/markdown/wrapper.js | 17 +++++++++++---- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/plugins/tiddlywiki/markdown/markdown-it-tiddlywiki.js b/plugins/tiddlywiki/markdown/markdown-it-tiddlywiki.js index ad55daa75d..e76470c4d1 100644 --- a/plugins/tiddlywiki/markdown/markdown-it-tiddlywiki.js +++ b/plugins/tiddlywiki/markdown/markdown-it-tiddlywiki.js @@ -133,25 +133,20 @@ function findNextMatch(ruleinfo,pos) { } // Add inline rule "macrocall" to parse <> -var MacroCallRegEx = /<<([^\s>"'=]+)[^>]*>>/g; function tw_macrocallinline(state,silent) { - var match, max, pos = state.pos; + var ruleinfo = pluginOpts.inlineRules.macrocallinline; - // Check start - max = state.posMax; - if(state.src.charCodeAt(pos) !== 0x3C || state.src.charCodeAt(pos+1) !== 0x3C /* << */|| pos + 3 >= max) { + var pos = state.pos; + var matchIndex = findNextMatch(ruleinfo,pos); + if(matchIndex === undefined || matchIndex !== pos) { return false; } - MacroCallRegEx.lastIndex = pos; - match = MacroCallRegEx.exec(state.src); - if(!match || match.index !== pos) { return false; } - if(!silent) { var token = state.push('tw_expr','',0); - token.content = state.src.slice(pos,pos+match[0].length); + token.content = state.src.slice(pos,ruleinfo.rule.nextCall.end); } - state.pos = MacroCallRegEx.lastIndex; + state.pos = ruleinfo.rule.nextCall.end; return true; } @@ -520,8 +515,10 @@ module.exports = function tiddlyWikiPlugin(markdown,options) { if(pluginOpts.inlineRules.transcludeinline) { md.inline.ruler.before('html_inline','tw_transcludeinline',tw_transcludeinline); } + if(pluginOpts.inlineRules.macrocallinline) { + md.inline.ruler.before('html_inline','tw_macrocallinline',tw_macrocallinline); + } - md.inline.ruler.before('html_inline','tw_macrocallinline',tw_macrocallinline); md.inline.ruler.at('html_inline',extendHtmlInline(md.inline.ruler.__rules__[md.inline.ruler.__find__('html_inline')].fn)); md.block.ruler.after('html_block','tw_block',tw_block,{ alt: [ 'paragraph', 'reference', 'blockquote' ] diff --git a/plugins/tiddlywiki/markdown/styles.tid b/plugins/tiddlywiki/markdown/styles.tid index 4185d43040..156801a06b 100644 --- a/plugins/tiddlywiki/markdown/styles.tid +++ b/plugins/tiddlywiki/markdown/styles.tid @@ -6,6 +6,9 @@ code-body: yes display: block; margin: 0px; } +span.markdown { + display: inline; +} .markdown hr { margin-top: 20px; margin-bottom: 20px; diff --git a/plugins/tiddlywiki/markdown/wrapper.js b/plugins/tiddlywiki/markdown/wrapper.js index 83da544b95..f1277ba74b 100755 --- a/plugins/tiddlywiki/markdown/wrapper.js +++ b/plugins/tiddlywiki/markdown/wrapper.js @@ -213,11 +213,20 @@ MarkdownParser.prototype.md = createMarkdownEngine(markdownOpts,pluginOpts); function MarkdownParser(type,text,options) { var env = {} var md = this.md; - var mdTree = md.parse(text,env); - var textToParse = '
\n' + md.renderer.render(mdTree,md.options,env) + '
'; + var mdTree, textToParse; - //console.log(JSON.stringify(mdTree,null,2)); - //console.log("\n----------------\n" + textToParse); + if(options.parseAsInline) { + mdTree = md.parseInline(text,env); + textToParse = '' + md.renderer.render(mdTree,md.options,env) + ''; + } else { + mdTree = md.parse(text,env); + textToParse = '
\n' + md.renderer.render(mdTree,md.options,env) + '
'; + } + + if($tw.log.MARKDOWN) { + console.log(JSON.stringify(mdTree,null,2)); + console.log("\n----------------\n" + textToParse); + } var wikiParser;