2012-05-26 17:30:32 +00:00
|
|
|
/*\
|
2012-06-10 12:40:19 +00:00
|
|
|
title: $:/core/modules/parsers/newwikitextparser/rules/classblock.js
|
2012-05-26 17:30:32 +00:00
|
|
|
type: application/javascript
|
2012-05-27 08:19:37 +00:00
|
|
|
module-type: wikitextrule
|
2012-05-26 17:30:32 +00:00
|
|
|
|
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.
|
2012-05-26 17:30:32 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.name = "class";
|
|
|
|
|
2012-05-26 23:22:58 +00:00
|
|
|
exports.blockParser = true;
|
|
|
|
|
2012-06-05 21:54:36 +00:00
|
|
|
exports.regExpString = "\\{\\{(?:[^\\{\\r\\n]+)\\{$\\r?\\n";
|
2012-05-26 17:30:32 +00:00
|
|
|
|
2012-05-28 14:51:52 +00:00
|
|
|
exports.parse = function(match,isBlock) {
|
2012-05-26 17:30:32 +00:00
|
|
|
var tree = [],
|
2012-06-05 21:54:36 +00:00
|
|
|
reStart = /\{\{([^\{\r\n]+){\r?\n/mg,
|
2012-06-10 16:26:54 +00:00
|
|
|
reEndString = "(\\}\\}\\}$(?:\\r?\\n)?)",
|
2012-05-26 17:30:32 +00:00
|
|
|
endMatch;
|
|
|
|
reStart.lastIndex = this.pos;
|
|
|
|
match = reStart.exec(this.source);
|
|
|
|
if(match) {
|
|
|
|
this.pos = match.index + match[0].length;
|
2012-06-14 16:40:27 +00:00
|
|
|
tree = this.parseBlocks(reEndString);
|
|
|
|
for(var t=0; t<tree.length; t++) {
|
|
|
|
tree[t].addClass(match[1]);
|
|
|
|
}
|
2012-05-26 17:30:32 +00:00
|
|
|
}
|
2012-06-07 12:09:22 +00:00
|
|
|
return tree;
|
2012-05-26 17:30:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|