mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-30 05:19:57 +00:00
feat: restore inline macro def
This commit is contained in:
parent
f0babe4388
commit
375df47b19
@ -55,9 +55,10 @@ exports.parse = function() {
|
||||
}
|
||||
}
|
||||
// Is the remainder of the \define line blank after the parameter close paren?
|
||||
var reEnd;
|
||||
var reEnd,inline = true;
|
||||
if(this.match[3]) {
|
||||
// If so, it is a multiline definition and the end of the body is marked with \end
|
||||
inline = false;
|
||||
reEnd = new RegExp("((?:^|\\r?\\n)[^\\S\\n\\r]*\\\\end[^\\S\\n\\r]*(?:" + $tw.utils.escapeRegExp(this.match[1]) + ")?(?:$|\\r?\\n))","mg");
|
||||
} else {
|
||||
// Otherwise, the end of the definition is marked by the end of the line
|
||||
@ -82,7 +83,8 @@ exports.parse = function() {
|
||||
attributes: {},
|
||||
children: [],
|
||||
params: params,
|
||||
isMacroDefinition: true
|
||||
isMacroDefinition: true,
|
||||
inline: inline && !!endMatch
|
||||
}];
|
||||
$tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"name",this.match[1]);
|
||||
$tw.utils.addAttributeToParseTreeNode(parseTreeNodes[0],"value",text);
|
||||
@ -95,6 +97,9 @@ exports.serialize = function(tree,serialize) {
|
||||
return param.name + (param.default ? ":" + param.default : "");
|
||||
}).join(",");
|
||||
var definition = tree.attributes.value.value;
|
||||
if(tree.inline) {
|
||||
return "\\define " + name + "(" + params + ") " + definition + "\n\n" + serialize(tree.children);
|
||||
}
|
||||
return "\\define " + name + "(" + params + ")\n" + definition + "\n\\end\n\n" + serialize(tree.children);
|
||||
};
|
||||
|
||||
|
@ -4,4 +4,6 @@ type: text/vnd.tiddlywiki
|
||||
|
||||
\define name(param:defaultvalue,param2:defaultvalue)
|
||||
definition text, including $param$ markers
|
||||
\end
|
||||
\end
|
||||
|
||||
\define lingo-base() $:/language/ControlPanel/Basics/
|
||||
|
@ -114,7 +114,12 @@ describe("WikiText parser tests", function() {
|
||||
it("should parse macro definitions", function() {
|
||||
expect(parse("\\define myMacro()\nnothing\n\\end\n")).toEqual(
|
||||
|
||||
[{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"myMacro"},"value":{"name":"value","type":"string","value":"nothing"}},"children":[],"params":[],"isMacroDefinition":true,"orderedAttributes":[{"name":"name","type":"string","value":"myMacro"},{"name":"value","type":"string","value":"nothing"}],"start":0,"end":30,"rule":"macrodef"}]
|
||||
[{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"myMacro"},"value":{"name":"value","type":"string","value":"nothing"}},"children":[],"params":[],"isMacroDefinition":true,"inline":false,"orderedAttributes":[{"name":"name","type":"string","value":"myMacro"},{"name":"value","type":"string","value":"nothing"}],"start":0,"end":30,"rule":"macrodef"}]
|
||||
|
||||
);
|
||||
expect(parse("\\define myMacro() nothing\n\n")).toEqual(
|
||||
|
||||
[{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"myMacro"},"value":{"name":"value","type":"string","value":"nothing"}},"children":[],"params":[],"isMacroDefinition":true,"inline":true,"orderedAttributes":[{"name":"name","type":"string","value":"myMacro"},{"name":"value","type":"string","value":"nothing"}],"start":0,"end":25,"rule":"macrodef"}]
|
||||
|
||||
);
|
||||
});
|
||||
@ -185,7 +190,7 @@ describe("WikiText parser tests", function() {
|
||||
it("should parse comment in pragma area. Comment will be invisible", function() {
|
||||
expect(parse("<!-- comment in pragma area -->\n\\define aMacro()\nnothing\n\\end\n")).toEqual(
|
||||
|
||||
[{"type":"void","children":[{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"aMacro"},"value":{"name":"value","type":"string","value":"nothing"}},"children":[],"params":[],"isMacroDefinition":true,"orderedAttributes":[{"name":"name","type":"string","value":"aMacro"},{"name":"value","type":"string","value":"nothing"}],"start":32,"end":61,"rule":"macrodef"}],"text":"<!-- comment in pragma area -->","start":0,"end":31,"rule":"commentblock"}]
|
||||
[{"type":"void","children":[{"type":"set","attributes":{"name":{"name":"name","type":"string","value":"aMacro"},"value":{"name":"value","type":"string","value":"nothing"}},"children":[],"params":[],"isMacroDefinition":true,"inline":false,"orderedAttributes":[{"name":"name","type":"string","value":"aMacro"},{"name":"value","type":"string","value":"nothing"}],"start":32,"end":61,"rule":"macrodef"}],"text":"<!-- comment in pragma area -->","start":0,"end":31,"rule":"commentblock"}]
|
||||
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user