1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-17 09:24:30 +00:00
TiddlyWiki5/core/modules/parsers/wikiparser/rules/block/classblock.js
2012-12-15 11:39:58 +00:00

50 lines
1.1 KiB
JavaScript

/*\
title: $:/core/modules/parsers/wikiparser/rules/block/classblock.js
type: application/javascript
module-type: wikiblockrule
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 = "classblock";
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /\{\{([^\{\r\n]+)\{\r?\n/mg;
};
exports.parse = function() {
var reEndString = "(\\}\\}\\}$(?:\\r?\\n)?)";
// Get the class
var classString = this.match[1];
// Move past the match
this.parser.pos = this.matchRegExp.lastIndex;
// Parse the body
var tree = this.parser.parseBlocks(reEndString);
for(var t=0; t<tree.length; t++) {
$tw.utils.addClassToParseTreeNode(tree[t],classString);
}
return tree;
};
})();