1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-07 07:50:26 +00:00

refactor: reuse block on inline when possible

This commit is contained in:
lin onetwo 2024-08-10 01:31:55 +08:00
parent 589241a406
commit 0adf638c1a
4 changed files with 12 additions and 63 deletions

View File

@ -71,8 +71,7 @@ exports.parse = function() {
return [node];
};
exports.serialize = function(tree) {
// Filter expression
exports.serialize = function(tree, serialize) {
var serialized = "{{{" + tree.attributes.filter.value;
// Tooltip text
if(tree.attributes.tooltip) serialized += "|" + tree.attributes.tooltip.value;

View File

@ -70,20 +70,10 @@ exports.parse = function() {
return [node];
};
exports.serialize = function(tree) {
// Filter expression
var serialized = "{{{" + tree.attributes.filter.value;
// Tooltip text
if(tree.attributes.tooltip) serialized += "|" + tree.attributes.tooltip.value;
// Template title
if(tree.attributes.template) serialized += "||" + tree.attributes.template.value;
serialized += "}}";
// Inline styles
if(tree.attributes.style) serialized += tree.attributes.style.value;
serialized += "}"
// CSS classes
if(tree.attributes.itemClass) serialized += "." + tree.attributes.itemClass.value.split(" ").join(".");
return serialized;
exports.serialize = function(tree, serialize) {
var filteredtranscludeblock = require("$:/core/modules/parsers/wikiparser/rules/filteredtranscludeblock.js");
var result = filteredtranscludeblock.serialize(tree, serialize);
return result.trimEnd();
};
})();

View File

@ -49,22 +49,10 @@ exports.parse = function() {
/*
Same as macrocallblock but without \n\n
*/
exports.serialize = function (node) {
// Start with macro opener
var result = "<<";
if(node.attributes && node.attributes["$variable"]) {
result += node.attributes["$variable"].value; // Add macro name
}
// Append ordered arguments if any
if(node.orderedAttributes) {
node.orderedAttributes.forEach(function (attr) {
if(attr.name !== "$variable") {
result += " " + '"' + attr.value + '"'; // Add each additional value
}
});
}
result += ">>";
return result;
exports.serialize = function (tree, serialize) {
var macrocallblock = require("$:/core/modules/parsers/wikiparser/rules/macrocallblock.js");
var result = macrocallblock.serialize(tree, serialize);
return result.trimEnd();
};
})();

View File

@ -85,37 +85,9 @@ exports.parse = function() {
};
exports.serialize = function(tree, serialize) {
var serialized = "{{";
// Check for tiddler attribute
if(tree.attributes.$tiddler) {
serialized += tree.attributes.$tiddler.value;
// Check for field attribute
if(tree.attributes.$field) {
serialized += "##" + tree.attributes.$field.value;
}
// Check for index attribute
if(tree.attributes.$index) {
serialized += "!!" + tree.attributes.$index.value;
}
}
// Check for template attribute
if(tree.attributes.$template) {
serialized += "||" + tree.attributes.$template.value;
}
// Check for parameters
var params = [];
for(var key in tree.attributes) {
if(key !== "$tiddler" && key !== "$field" && key !== "$index" && key !== "$template") {
params.push(tree.attributes[key].value);
}
}
if(params.length > 0) {
serialized += "|" + params.join("|");
}
// Close the serialized string
serialized += "}}";
// Return the complete serialized string
return serialized;
var transcludeblock = require("$:/core/modules/parsers/wikiparser/rules/transcludeblock.js");
var result = transcludeblock.serialize(tree, serialize);
return result.trimEnd();
};
})();