1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-04-15 15:23:17 +00:00

refactor: use serialize in rules

This commit is contained in:
lin onetwo 2024-06-13 01:34:18 +08:00
parent f882cbd7af
commit be3f037a57
3 changed files with 9 additions and 9 deletions

View File

@ -57,7 +57,7 @@ exports.parse = function() {
}];
};
exports.getText = function(tree) {
exports.serialize = function(tree) {
return "\n```" + tree.attributes.language.value + "\n" + tree.attributes.code.value + "\n```\n";
}

View File

@ -31,8 +31,8 @@ exports.parse = function() {
return [{type: "element", tag: "hr"}];
};
exports.getText = function() {
return "---";
exports.serialize = function() {
return "\n---\n";
}
})();

View File

@ -137,15 +137,15 @@ exports.serializeParseTree = function serializeParseTree(tree, tiddlerType) {
output.push(tree.text);
} else {
var Parser = $tw.wiki.getParser(tiddlerType);
var Rule = Parser.prototype.blockRuleClasses[tree.type] ||
Parser.prototype.inlineRuleClasses[tree.type] ||
Parser.prototype.pragmaRuleClasses[tree.type];
if(Rule && Rule.prototype.getText) {
output.push(Rule.prototype.getText(tree));
var Rule = Parser.prototype.blockRuleClasses[tree.rule] ||
Parser.prototype.inlineRuleClasses[tree.rule] ||
Parser.prototype.pragmaRuleClasses[tree.rule];
if(Rule && Rule.prototype.serialize) {
output.push(Rule.prototype.serialize(tree));
}
}
if(tree.children) {
return getParseTreeText(tree.children);
return serializeParseTree(tree.children);
}
}
return output.join("");