2012-06-14 17:18:32 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/parsers/newwikitextparser/rules/styleblock.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: wikitextrule
|
|
|
|
|
|
|
|
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 = "style";
|
|
|
|
|
|
|
|
exports.blockParser = true;
|
|
|
|
|
2012-06-14 18:03:51 +00:00
|
|
|
exports.regExpString = "@@[a-zA-Z0-9_\\-]+:.*;$";
|
2012-06-14 17:18:32 +00:00
|
|
|
|
|
|
|
exports.parse = function(match,isBlock) {
|
|
|
|
var styles = {},
|
|
|
|
tree = [],
|
2012-06-14 18:03:51 +00:00
|
|
|
reStyleSpecififer = /@@([a-zA-Z0-9_\-]+):(.*);((?:\r?\n)?)/mg,
|
2012-06-14 17:18:32 +00:00
|
|
|
reEndString = "@@",
|
|
|
|
endMatch;
|
|
|
|
// Look for the first style specifier
|
|
|
|
reStyleSpecififer.lastIndex = this.pos;
|
|
|
|
match = reStyleSpecififer.exec(this.source);
|
2012-06-14 17:49:51 +00:00
|
|
|
while(match && match.index === this.pos) {
|
2012-06-14 17:18:32 +00:00
|
|
|
// Save the style specified
|
2012-06-14 17:49:51 +00:00
|
|
|
styles[match[1]] = match[2].trim();
|
2012-06-14 17:18:32 +00:00
|
|
|
// Look to see if there is a further style specifier
|
|
|
|
this.pos = match.index + match[0].length;
|
|
|
|
reStyleSpecififer.lastIndex = this.pos;
|
|
|
|
match = reStyleSpecififer.exec(this.source);
|
|
|
|
}
|
|
|
|
// Parse until we get to the end marker
|
|
|
|
tree = this.parseBlocks(reEndString);
|
|
|
|
for(var t=0; t<tree.length; t++) {
|
|
|
|
tree[t].addStyles(styles);
|
|
|
|
}
|
|
|
|
return tree;
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|