mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-06 13:56:45 +00:00
feat: add rule: 'parseBlock' metadata
This commit is contained in:
parent
05dec729a0
commit
1a6a071a29
@ -259,7 +259,7 @@ WikiParser.prototype.parseBlock = function(terminatorRegExpString) {
|
|||||||
var start = this.pos;
|
var start = this.pos;
|
||||||
var children = this.parseInlineRun(terminatorRegExp);
|
var children = this.parseInlineRun(terminatorRegExp);
|
||||||
var end = this.pos;
|
var end = this.pos;
|
||||||
return [{type: "element", tag: "p", children: children, start: start, end: end }];
|
return [{type: "element", tag: "p", children: children, start: start, end: end, rule: 'parseBlock' }];
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -124,9 +124,10 @@ exports.getParseTreeText = function getParseTreeText(tree) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Utility to get the (similarly but not 1:1 equal) original wikitext of a parse tree node or array of nodes
|
Utility to get the (similarly but not 1:1 equal) original wikitext of a parse tree node or array of nodes.
|
||||||
|
Based on `node.rule` metadata added in `wikiparser.js`.
|
||||||
*/
|
*/
|
||||||
exports.serializeParseTree = function serializeParseTree(tree, tiddlerType) {
|
exports.serializeParseTree = function serializeParseTree(tree,tiddlerType) {
|
||||||
var output = [];
|
var output = [];
|
||||||
if($tw.utils.isArray(tree)) {
|
if($tw.utils.isArray(tree)) {
|
||||||
$tw.utils.each(tree,function(node) {
|
$tw.utils.each(tree,function(node) {
|
||||||
@ -141,12 +142,11 @@ exports.serializeParseTree = function serializeParseTree(tree, tiddlerType) {
|
|||||||
Parser.prototype.inlineRuleClasses[tree.rule] ||
|
Parser.prototype.inlineRuleClasses[tree.rule] ||
|
||||||
Parser.prototype.pragmaRuleClasses[tree.rule];
|
Parser.prototype.pragmaRuleClasses[tree.rule];
|
||||||
if(Rule && Rule.prototype.serialize) {
|
if(Rule && Rule.prototype.serialize) {
|
||||||
output.push(Rule.prototype.serialize(tree));
|
output.push(Rule.prototype.serialize(tree,serializeParseTree));
|
||||||
|
} else if(tree.rule === "parseBlock") {
|
||||||
|
output.push(serializeParseTree(tree.children,tiddlerType),"\n\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(tree.children) {
|
|
||||||
return serializeParseTree(tree.children);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return output.join("");
|
return output.join("");
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user