From 069181d615a391bec4c7ad37b66dfc7ffc3128f2 Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Wed, 19 Feb 2025 15:38:49 +0800 Subject: [PATCH] DEBUG: render result and diff below body only on browser DEBUG: render result below body only on browser DEBUG: render result below body DEBUG: fix build DEBUG: show render result as ViewTemplate --- core/modules/filters/serializeparsetree.js | 29 ++++++++++++++++++++++ core/ui/ViewTemplate/body/default.tid | 14 +++++++++++ 2 files changed, 43 insertions(+) create mode 100644 core/modules/filters/serializeparsetree.js diff --git a/core/modules/filters/serializeparsetree.js b/core/modules/filters/serializeparsetree.js new file mode 100644 index 000000000..04796a2c9 --- /dev/null +++ b/core/modules/filters/serializeparsetree.js @@ -0,0 +1,29 @@ +/*\ +title: $:/core/modules/filters/serializeparsetree.js +type: application/javascript +module-type: filteroperator + +Filter operator for serializing JSON string of Abstract Syntax Tree (AST) of Wiki parse tree to a raw WikiText string. + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Export our filter function +*/ +exports.serializeparsetree = function(source,operator,options) { + var results = []; + source(function(tiddler,title) { + var parseTreeObject = $tw.utils.parseJSONSafe(title); + if(parseTreeObject) { + results.push($tw.utils.serializeParseTree(parseTreeObject)); + } + }); + return results; +}; + +})(); diff --git a/core/ui/ViewTemplate/body/default.tid b/core/ui/ViewTemplate/body/default.tid index 5416c6e07..cc2453ecf 100644 --- a/core/ui/ViewTemplate/body/default.tid +++ b/core/ui/ViewTemplate/body/default.tid @@ -6,3 +6,17 @@ code-body: yes <$transclude tiddler="$:/language/MissingTiddler/Hint"/> + +<%if [[$:/info/browser]text[yes]] %> + <$wikify text={{!!text}} name=parsetree output=parsetree > + <$let text2={{{[serializeparsetree[]]}}}> + <$wikify name=rendered text=<> output=html > + + <$diff-text source={{!!text}} dest=<>/> + + <> + + + + +<%endif%> \ No newline at end of file