1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2026-04-30 10:41:30 +00:00

First commit

This commit is contained in:
jeremy@jermolene.com
2022-10-20 18:07:36 +01:00
parent 24dbf69180
commit b3982efcd6
3 changed files with 57 additions and 5 deletions

View File

@@ -27,7 +27,7 @@ Instantiate parse rule
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /^\\define\s+([^(\s]+)\(\s*([^)]*)\)(\s*\r?\n)?/mg;
this.matchRegExp = /^(\\+)define\s+([^(\s]+)\(\s*([^)]*)\)(\s*\r?\n)?/mg;
};
/*
@@ -37,7 +37,7 @@ exports.parse = function() {
// Move past the macro name and parameters
this.parser.pos = this.matchRegExp.lastIndex;
// Parse the parameters
var paramString = this.match[2],
var paramString = this.match[3],
params = [];
if(paramString !== "") {
var reParam = /\s*([A-Za-z0-9\-_]+)(?:\s*:\s*(?:"""([\s\S]*?)"""|"([^"]*)"|'([^']*)'|\[\[([^\]]*)\]\]|([^"'\s]+)))?/mg,
@@ -56,9 +56,9 @@ exports.parse = function() {
}
// Is this a multiline definition?
var reEnd;
if(this.match[3]) {
if(this.match[4]) {
// If so, the end of the body is marked with \end
reEnd = /(\r?\n\\end[^\S\n\r]*(?:$|\r?\n))/mg;
reEnd = new RegExp("(\\r?\\n" + $tw.utils.repeat("\\\\",this.match[1].length) + "end[^\\S\\n\\r]*(?:$|\\r?\\n))","mg");
} else {
// Otherwise, the end of the definition is marked by the end of the line
reEnd = /($|\r?\n)/mg;
@@ -80,7 +80,7 @@ exports.parse = function() {
return [{
type: "set",
attributes: {
name: {type: "string", value: this.match[1]},
name: {type: "string", value: this.match[2]},
value: {type: "string", value: text}
},
children: [],

View File

@@ -0,0 +1,36 @@
title: Macros/NestedMacros
description: Nested Macros
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
\define outer()
\whitespace trim
\\define middle()
\whitespace trim
\\\\define inner()
\whitespace trim
Jaguar
\\\\end
<<inner>>
\\end
<<middle>>
\end
<<outer>>
+
title: ExpectedResult
<p>Jaguar</p>

View File

@@ -119,6 +119,22 @@ describe("WikiText parser tests", function() {
);
});
it("should parse macro definitions with two backslashes", function() {
expect(parse("\\\\define myMacro()\nnothing\n\\\\end\n")).toEqual(
[ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], params : [ ], isMacroDefinition : true } ]
);
});
it("should parse macro definitions with four backslashes", function() {
expect(parse("\\\\\\\\define myMacro()\nnothing\n\\\\\\\\end\n")).toEqual(
[ { type : 'set', attributes : { name : { type : 'string', value : 'myMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], params : [ ], isMacroDefinition : true } ]
);
});
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(