1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-13 15:59:42 +00:00
TiddlyWiki5/core/modules/parsers/wikitextparser/rules/classblock.js

51 lines
1.1 KiB
JavaScript
Raw Normal View History

/*\
2012-11-15 12:53:10 +00:00
title: $:/core/modules/parsers/wikitextparser/rules/classblock.js
type: application/javascript
module-type: wikitextrule
2012-06-05 21:54:36 +00:00
Wiki text block rule for assigning classes to paragraphs and other blocks. For example:
{{{
{{myClass{
This paragraph will have the CSS class `myClass`.
* The `<ul>` around this list will also have the class `myClass`
* List item 2
}}}
}}}
Note that the opening and closing braces both must be immediately followed by a newline.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "class";
exports.blockParser = true;
2012-06-05 21:54:36 +00:00
exports.regExpString = "\\{\\{(?:[^\\{\\r\\n]+)\\{$\\r?\\n";
exports.parse = function(match,isBlock) {
var tree = [],
2012-11-06 17:21:56 +00:00
reStart = /\{\{([^\{\r\n]+)\{\r?\n/mg,
reEndString = "(\\}\\}\\}$(?:\\r?\\n)?)",
endMatch;
reStart.lastIndex = this.pos;
match = reStart.exec(this.source);
if(match) {
this.pos = match.index + match[0].length;
tree = this.parseBlocks(reEndString);
for(var t=0; t<tree.length; t++) {
tree[t].addClass(match[1]);
}
}
return tree;
};
})();