1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-12 07:19:44 +00:00
TiddlyWiki5/core/modules/parsers/newwikitextparser/rules/coderun.js

47 lines
942 B
JavaScript
Raw Normal View History

2012-06-02 08:41:21 +00:00
/*\
title: $:/core/modules/parsers/newwikitextparser/rules/coderun.js
2012-06-02 08:41:21 +00:00
type: application/javascript
module-type: wikitextrule
2012-06-05 21:54:36 +00:00
Wiki text run rule for code runs. For example:
{{{
This is a {{{code run}} and `so is this`.
}}}
2012-06-02 08:41:21 +00:00
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "coderun";
2012-06-02 08:41:21 +00:00
exports.runParser = true;
2012-06-02 09:15:52 +00:00
exports.regExpString = "(?:\\{\\{\\{)|(?:`)";
2012-06-02 08:41:21 +00:00
exports.parse = function(match,isBlock) {
this.pos = match.index + match[0].length;
2012-06-02 09:15:52 +00:00
var regExp,
text;
if(match[0] === "{{{") {
regExp = /(\}\}\})/mg;
} else {
regExp = /(`)/mg;
}
regExp.lastIndex = this.pos;
match = regExp.exec(this.source);
if(match) {
text = this.source.substring(this.pos,match.index);
this.pos = match.index + match[0].length;
} else {
text = this.source.substr(this.pos);
this.pos = this.sourceLength;
}
return [$tw.Tree.Element("code",{},[$tw.Tree.Text(text)])];
2012-06-02 08:41:21 +00:00
};
})();