2012-05-26 17:30:32 +00:00
|
|
|
/*\
|
2012-06-02 08:54:00 +00:00
|
|
|
title: $:/core/modules/parsers/newwikitextparser/rules/html.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
|
|
|
|
|
|
|
Wiki text block rule for block level HTML elements
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.name = "html";
|
|
|
|
|
2012-05-26 23:22:58 +00:00
|
|
|
exports.blockParser = true;
|
|
|
|
exports.runParser = true;
|
|
|
|
|
2012-05-26 17:30:32 +00:00
|
|
|
exports.regExpString = "<[A-Za-z]+\\s*[^>]*>";
|
|
|
|
|
2012-05-28 14:51:52 +00:00
|
|
|
exports.parse = function(match,isBlock) {
|
2012-05-26 17:30:32 +00:00
|
|
|
var reStart = /<([A-Za-z]+)(\s*[^>]*)>/mg,
|
|
|
|
reAttr = /\s*([A-Za-z\-_]+)(?:\s*=\s*(?:("[^"]*")|('[^']*')|([^"'\s]+)))?/mg;
|
|
|
|
reStart.lastIndex = this.pos;
|
|
|
|
var startMatch = reStart.exec(this.source);
|
|
|
|
if(startMatch && startMatch.index === this.pos) {
|
|
|
|
var attrMatch = reAttr.exec(startMatch[2]),
|
|
|
|
attributes = {};
|
|
|
|
while(attrMatch) {
|
|
|
|
var name = attrMatch[1],
|
|
|
|
value;
|
|
|
|
if(attrMatch[2]) { // Double quoted
|
|
|
|
value = attrMatch[2].substring(1,attrMatch[2].length-1);
|
|
|
|
} else if(attrMatch[3]) { // Single quoted
|
|
|
|
value = attrMatch[3].substring(1,attrMatch[3].length-1);
|
|
|
|
} else if(attrMatch[4]) { // Unquoted
|
|
|
|
value = attrMatch[4];
|
|
|
|
} else { // Valueless
|
|
|
|
value = true; // TODO: We should have a way of indicating we want an attribute without a value
|
|
|
|
}
|
|
|
|
attributes[name] = value;
|
|
|
|
attrMatch = reAttr.exec(startMatch[2]);
|
|
|
|
}
|
|
|
|
this.pos = startMatch.index + startMatch[0].length;
|
|
|
|
var reEnd = new RegExp("(</" + startMatch[1] + ">)","mg"),
|
|
|
|
element = $tw.Tree.Element(startMatch[1],attributes,this.parseRun(reEnd));
|
|
|
|
reEnd.lastIndex = this.pos;
|
|
|
|
match = reEnd.exec(this.source);
|
|
|
|
if(match && match.index === this.pos) {
|
|
|
|
this.pos = match.index + match[0].length;
|
|
|
|
}
|
|
|
|
return [element];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|