mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-11-26 12:14:51 +00:00
Allow newlines within filtered transclusions (#6421)
* Allow newlines within filtered transclusions * Docs
This commit is contained in:
@@ -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) {
|
exports.parseAttribute = function(source,pos) {
|
||||||
var node = {
|
var node = {
|
||||||
@@ -248,7 +248,7 @@ exports.parseAttribute = function(source,pos) {
|
|||||||
// Define our regexps
|
// Define our regexps
|
||||||
var reAttributeName = /([^\/\s>"'=]+)/g,
|
var reAttributeName = /([^\/\s>"'=]+)/g,
|
||||||
reUnquotedAttribute = /([^\/\s<>"'=]+)/g,
|
reUnquotedAttribute = /([^\/\s<>"'=]+)/g,
|
||||||
reFilteredValue = /\{\{\{(.+?)\}\}\}/g,
|
reFilteredValue = /\{\{\{([\S\s]+?)\}\}\}/g,
|
||||||
reIndirectValue = /\{\{([^\}]+)\}\}/g;
|
reIndirectValue = /\{\{([^\}]+)\}\}/g;
|
||||||
// Skip whitespace
|
// Skip whitespace
|
||||||
pos = $tw.utils.skipWhiteSpace(source,pos);
|
pos = $tw.utils.skipWhiteSpace(source,pos);
|
||||||
|
|||||||
@@ -128,6 +128,21 @@ describe("HTML tag new parser tests", function() {
|
|||||||
expect($tw.utils.parseAttribute("p=\"blah\" ",0)).toEqual(
|
expect($tw.utils.parseAttribute("p=\"blah\" ",0)).toEqual(
|
||||||
{ type : 'string', start : 0, name : 'p', value : 'blah', end : 8 }
|
{ 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(
|
expect($tw.utils.parseAttribute("p=blah ",0)).toEqual(
|
||||||
{ type : 'string', start : 0, name : 'p', value : 'blah', end : 6 }
|
{ type : 'string', start : 0, name : 'p', value : 'blah', end : 6 }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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(
|
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 } ]
|
[ { 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() {
|
it("should parse inline macro calls", function() {
|
||||||
expect(parse("<<john>><<paul>><<george>><<ringo>>")).toEqual(
|
expect(parse("<<john>><<paul>><<george>><<ringo>>")).toEqual(
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
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:
|
This example shows how to add a prefix to a value:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user