1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-24 17:10:29 +00:00

Introduce filtered transclusion syntax

This commit is contained in:
Jeremy Ruston 2012-12-23 10:37:18 +00:00
parent 05ccb85759
commit c3a2a24b76
2 changed files with 68 additions and 1 deletions

View File

@ -0,0 +1,65 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/filteredtranscludeblock.js
type: application/javascript
module-type: wikirule
Wiki text rule for block-level filtered transclusion. For example:
```
{{{ [tag[docs]] }}}
{{{ [tag[docs]] |tooltip}}}
{{{ [tag[docs]] ||TemplateTitle}}}
{{{ [tag[docs]] |tooltip||TemplateTitle}}}
{{{ [tag[docs]] }}width:40;height:50;}.class.class
```
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "filteredtransclude";
exports.types = {block: true};
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /\{\{\{([^\{\}\|]+)(?:\|([^\|\{\}]+))?(?:\|\|([^\|\{\}]+))?\}\}([^\}]*)\}(?:\.(\S+))?(?:\r?\n|$)/mg;
};
exports.parse = function() {
// Move past the match
this.parser.pos = this.matchRegExp.lastIndex;
// Get the match details
var filter = this.match[1],
tooltip = this.match[2],
template = this.match[3],
style = this.match[4],
classes = this.match[5];
// Return the list widget
var node = {
type: "widget",
tag: "list",
attributes: {
filter: {type: "string", value: filter}
},
isBlock: true
};
if(tooltip) {
node.attributes.tooltip = {type: "string", value: tooltip};
}
if(template) {
node.attributes.template = {type: "string", value: template};
}
if(style) {
node.attributes.style = {type: "string", value: style};
}
if(classes) {
node.attributes["itemClass"] = {type: "string", value: classes.split(".").join(" ")};
}
return [node];
};
})();

View File

@ -14,6 +14,8 @@ New paragraph
*.disabled Is a *.disabled Is a
* List!! * List!!
{{{ [tag[docs]tag[introduction]sort[title]] ||$:/templates/NewViewTemplate}}}.anotherClassy
<<me red green>> <<me red green>>
Inline macro call: <<me red green>> Inline macro call: <<me red green>>
@ -23,7 +25,7 @@ Inline macro call: <<me red green>>
| this | is | a | table | | this | is | a | table |
| yes | indeed |>| it is | | yes | indeed |>| it is |
{{Acknowledgements|with a tooltip}width:40;height:50;background-color:red;}.one {{Acknowledgements|with a tooltip||$:/templates/NewViewTemplate}width:40;height:50;background-color:red;}.one
And this is an inline transclusion {{Acknowledgements}width:40;height:50;}.one And this is an inline transclusion {{Acknowledgements}width:40;height:50;}.one