1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-18 03:19:55 +00:00

Allow newlines within filtered transclusions (#6421)

* Allow newlines within filtered transclusions

* Docs
This commit is contained in:
Jeremy Ruston 2022-02-21 15:28:21 +00:00 committed by GitHub
parent ab3109d84b
commit 5378b45c40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 3 deletions

View File

@ -239,7 +239,7 @@ exports.parseFilterVariable = function(source) {
};
/*
Look for an HTML attribute definition. Returns null if not found, otherwise returns {type: "attribute", name:, valueType: "string|indirect|macro", value:, start:, end:,}
Look for an HTML attribute definition. Returns null if not found, otherwise returns {type: "attribute", name:, type: "filtered|string|indirect|macro", value|filter|textReference:, start:, end:,}
*/
exports.parseAttribute = function(source,pos) {
var node = {
@ -248,7 +248,7 @@ exports.parseAttribute = function(source,pos) {
// Define our regexps
var reAttributeName = /([^\/\s>"'=]+)/g,
reUnquotedAttribute = /([^\/\s<>"'=]+)/g,
reFilteredValue = /\{\{\{(.+?)\}\}\}/g,
reFilteredValue = /\{\{\{([\S\s]+?)\}\}\}/g,
reIndirectValue = /\{\{([^\}]+)\}\}/g;
// Skip whitespace
pos = $tw.utils.skipWhiteSpace(source,pos);

View File

@ -128,6 +128,21 @@ describe("HTML tag new parser tests", function() {
expect($tw.utils.parseAttribute("p=\"blah\" ",0)).toEqual(
{ type : 'string', start : 0, name : 'p', value : 'blah', end : 8 }
);
expect($tw.utils.parseAttribute("p=\"bl\nah\" ",0)).toEqual(
{ type : 'string', start : 0, name : 'p', value : 'bl\nah', end : 9 }
);
expect($tw.utils.parseAttribute("p={{{blah}}} ",0)).toEqual(
{ type : 'filtered', start : 0, name : 'p', filter : 'blah', end : 12 }
);
expect($tw.utils.parseAttribute("p={{{bl\nah}}} ",0)).toEqual(
{ type : 'filtered', start : 0, name : 'p', filter : 'bl\nah', end : 13 }
);
expect($tw.utils.parseAttribute("p={{{ [{$:/layout}] }}} ",0)).toEqual(
{ type : 'filtered', start : 0, name : 'p', filter : ' [{$:/layout}] ', end : 23 }
);
expect($tw.utils.parseAttribute("p={{blah}} ",0)).toEqual(
{ type : 'indirect', start : 0, name : 'p', textReference : 'blah', end : 10 }
);
expect($tw.utils.parseAttribute("p=blah ",0)).toEqual(
{ type : 'string', start : 0, name : 'p', value : 'blah', end : 6 }
);

View File

@ -119,7 +119,7 @@ describe("WikiText parser tests", function() {
);
});
it("should parse comment in pragma area. Comment will be INVISIBLE", 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 : 'set', attributes : { name : { type : 'string', value : 'aMacro' }, value : { type : 'string', value : 'nothing' } }, children : [ ], params : [ ], isMacroDefinition : true } ]
@ -127,6 +127,19 @@ describe("WikiText parser tests", function() {
);
});
it("should block mode filtered transclusions", function() {
expect(parse("{{{ filter }}}")).toEqual(
[ { type: 'list', attributes: { filter: { type: 'string', value: ' filter ' } }, isBlock: true } ]
);
expect(parse("{{{ fil\nter }}}")).toEqual(
[ { type: 'list', attributes: { filter: { type: 'string', value: ' fil\nter ' } }, isBlock: true } ]
);
});
it("should parse inline macro calls", function() {
expect(parse("<<john>><<paul>><<george>><<ringo>>")).toEqual(

View File

@ -131,6 +131,8 @@ Variable attribute values are indicated with double angle brackets around a [[ma
Filtered attribute values are indicated with triple curly braces around a [[Filter Expression]]. The value will be the first item in the resulting list, or the empty string if the list is empty.
<<.from-version "5.2.2">> To improve readability, newlines can be included anywhere that whitespace is allowed within filtered attributes.
This example shows how to add a prefix to a value:
```