2012-12-15 11:39:58 +00:00
|
|
|
/*\
|
2012-12-20 16:41:06 +00:00
|
|
|
title: $:/core/modules/parsers/wikiparser/rules/classinline.js
|
2012-12-15 11:39:58 +00:00
|
|
|
type: application/javascript
|
2012-12-20 16:02:03 +00:00
|
|
|
module-type: wikirule
|
2012-12-15 11:39:58 +00:00
|
|
|
|
2012-12-20 12:18:38 +00:00
|
|
|
Wiki text inline rule for assigning classes to runs of text. For example:
|
2012-12-15 11:39:58 +00:00
|
|
|
|
|
|
|
{{{
|
|
|
|
{{myClass{This text will have the CSS class `myClass`.
|
|
|
|
|
|
|
|
* This will not be recognised as a list
|
|
|
|
|
|
|
|
List item 2}}}
|
|
|
|
}}}
|
|
|
|
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
2012-12-20 12:18:38 +00:00
|
|
|
exports.name = "classinline";
|
2012-12-20 16:02:03 +00:00
|
|
|
exports.types = {inline: true};
|
2012-12-15 11:39:58 +00:00
|
|
|
|
|
|
|
exports.init = function(parser) {
|
|
|
|
this.parser = parser;
|
|
|
|
// Regexp to match
|
|
|
|
this.matchRegExp = /\{\{([^\{\r\n]+)\{/mg;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.parse = function() {
|
|
|
|
var reEnd = /(\}\}\})/g;
|
|
|
|
// Get the class
|
|
|
|
var classString = this.match[1];
|
|
|
|
// Move past the match
|
|
|
|
this.parser.pos = this.matchRegExp.lastIndex;
|
|
|
|
// Parse the run up to the terminator
|
2012-12-20 12:18:38 +00:00
|
|
|
var tree = this.parser.parseInlineRun(reEnd,{eatTerminator: true});
|
2012-12-15 11:39:58 +00:00
|
|
|
// Return the classed span
|
|
|
|
return [{
|
|
|
|
type: "element",
|
|
|
|
tag: "span",
|
|
|
|
attributes: {
|
|
|
|
"class": {type: "string", value: classString}
|
|
|
|
},
|
|
|
|
children: tree
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|