mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-30 05:19:57 +00:00
fix: positional attribute in macro call
This commit is contained in:
parent
53296a484c
commit
72dd18dfa5
@ -388,28 +388,33 @@ exports.parseAttribute = function(source,pos) {
|
||||
/*
|
||||
Serialize a parsed attribute node
|
||||
*/
|
||||
exports.serializeAttribute = function(node) {
|
||||
exports.serializeAttribute = function(node,options) {
|
||||
options = options || {};
|
||||
if(!node || typeof node !== "object" || !node.name || !node.type) {
|
||||
return null;
|
||||
}
|
||||
var attributeString = node.name;
|
||||
// If name is number, means it is a positional attribute and name is omitted
|
||||
var positional = parseInt(node.name) >= 0,
|
||||
// `=` in a widget and might be `:` in a macro
|
||||
assign = positional ? "" : (options.assignmentSymbol || "="),
|
||||
attributeString = positional ? "" : node.name;
|
||||
if(node.type === "string") {
|
||||
if(node.value === "true") {
|
||||
return attributeString;
|
||||
}
|
||||
attributeString += '="' + node.value + '"';
|
||||
attributeString += assign + '"' + node.value + '"';
|
||||
} else if(node.type === "filtered") {
|
||||
attributeString += "={{{" + node.filter + "}}}";
|
||||
attributeString += assign + "{{{" + node.filter + "}}}";
|
||||
} else if(node.type === "indirect") {
|
||||
attributeString += "={{" + node.textReference + "}}";
|
||||
attributeString += assign + "{{" + node.textReference + "}}";
|
||||
} else if(node.type === "substituted") {
|
||||
attributeString += "=`" + node.rawValue + "`";
|
||||
attributeString += assign + "`" + node.rawValue + "`";
|
||||
} else if(node.type === "macro") {
|
||||
if(node.value && typeof node.value === "object" && node.value.type === "macrocall") {
|
||||
var params = node.value.params.map(function(param) {
|
||||
return param.value;
|
||||
}).join(" ");
|
||||
attributeString += "=<<" + node.value.name + " " + params + ">>";
|
||||
attributeString += assign + "<<" + node.value.name + " " + params + ">>";
|
||||
} else {
|
||||
// Unsupported macro structure
|
||||
return null;
|
||||
|
@ -64,9 +64,9 @@ exports.serialize = function (node) {
|
||||
}
|
||||
// Append ordered arguments if any
|
||||
if(node.orderedAttributes) {
|
||||
node.orderedAttributes.forEach(function (attr) {
|
||||
if(attr.name !== "$variable") {
|
||||
result += " " + '"' + attr.value + '"';
|
||||
node.orderedAttributes.forEach(function (attribute) {
|
||||
if(attribute.name !== "$variable") {
|
||||
result += " " + $tw.utils.serializeAttribute(attribute,{assignmentSymbol:":"});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -4,4 +4,6 @@ type: text/vnd.tiddlywiki
|
||||
|
||||
<<name "value" "value2">>
|
||||
|
||||
<<.def "macro calls">>
|
||||
<<.def "macro calls">>
|
||||
|
||||
<<alert "primary" "primary alert" width:"60%">>
|
||||
|
@ -2,4 +2,4 @@ tags: $:/tags/wikitext-serialize-test-spec
|
||||
title: Serialize/MacroCallInline
|
||||
type: text/vnd.tiddlywiki
|
||||
|
||||
These are macro calls in a line: <<name "value" "value2">> and <<.def "macro calls">>
|
||||
These are macro calls in a line: <<name "value" "value2">> and <<.def "macro calls">> <<alert "primary" "primary alert" width:"60%">>
|
||||
|
Loading…
Reference in New Issue
Block a user