2012-12-15 11:39:58 +00:00
|
|
|
/*\
|
2012-12-28 22:08:32 +00:00
|
|
|
title: $:/core/modules/parsers/wikiparser/rules/commentblock.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-28 22:08:32 +00:00
|
|
|
Wiki text block rule for HTML comments. For example:
|
2012-12-15 11:39:58 +00:00
|
|
|
|
2012-12-22 23:09:44 +00:00
|
|
|
```
|
2012-12-15 11:39:58 +00:00
|
|
|
<!-- This is a comment -->
|
2021-06-14 16:39:56 +00:00
|
|
|
\define macroX()
|
|
|
|
<!-- This is a comment -->
|
|
|
|
xxxx
|
|
|
|
\end
|
|
|
|
<!-- This is a comment -->
|
|
|
|
|
2012-12-22 23:09:44 +00:00
|
|
|
```
|
2012-12-15 11:39:58 +00:00
|
|
|
|
2014-02-12 15:24:03 +00:00
|
|
|
Note that the syntax for comments is simplified to an opening "<!--" sequence and a closing "-->" sequence -- HTML itself implements a more complex format (see http://ostermiller.org/findhtmlcomment.html)
|
|
|
|
|
2012-12-15 11:39:58 +00:00
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
2012-12-28 22:08:32 +00:00
|
|
|
exports.name = "commentblock";
|
2021-06-14 16:39:56 +00:00
|
|
|
exports.types = {block:true, pragma:true};
|
2012-12-15 11:39:58 +00:00
|
|
|
|
|
|
|
exports.init = function(parser) {
|
|
|
|
this.parser = parser;
|
2014-08-30 19:44:26 +00:00
|
|
|
this.matchRegExp = /<!--/mg;
|
|
|
|
this.endMatchRegExp = /-->/mg;
|
2014-02-12 15:24:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.findNextMatch = function(startPos) {
|
|
|
|
this.matchRegExp.lastIndex = startPos;
|
|
|
|
this.match = this.matchRegExp.exec(this.parser.source);
|
|
|
|
if(this.match) {
|
2021-01-13 11:48:42 +00:00
|
|
|
this.endMatchRegExp.lastIndex = this.match.index + this.match[0].length;
|
2014-02-12 15:24:03 +00:00
|
|
|
this.endMatch = this.endMatchRegExp.exec(this.parser.source);
|
|
|
|
if(this.endMatch) {
|
|
|
|
return this.match.index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undefined;
|
2012-12-15 11:39:58 +00:00
|
|
|
};
|
|
|
|
|
2012-12-20 15:43:12 +00:00
|
|
|
exports.parse = function() {
|
2012-12-15 11:39:58 +00:00
|
|
|
// Move past the match
|
2014-02-12 15:24:03 +00:00
|
|
|
this.parser.pos = this.endMatchRegExp.lastIndex;
|
2012-12-15 11:39:58 +00:00
|
|
|
// Don't return any elements
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|