mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-15 00:39:42 +00:00
79 lines
1.4 KiB
JavaScript
79 lines
1.4 KiB
JavaScript
|
/*\
|
||
|
title: $:/core/modules/parsers/wikiparser/rules/run/emphasis.js
|
||
|
type: application/javascript
|
||
|
module-type: wikirunrule
|
||
|
|
||
|
Wiki text run rule for emphasis. For example:
|
||
|
|
||
|
{{{
|
||
|
This is ''bold'' text
|
||
|
|
||
|
This is //italic// text
|
||
|
|
||
|
This is __underlined__ text
|
||
|
|
||
|
This is ^^superscript^^ text
|
||
|
|
||
|
This is ,,subscript,, text
|
||
|
|
||
|
This is ~~strikethrough~~ text
|
||
|
}}}
|
||
|
|
||
|
\*/
|
||
|
(function(){
|
||
|
|
||
|
/*jslint node: true, browser: true */
|
||
|
/*global $tw: false */
|
||
|
"use strict";
|
||
|
|
||
|
exports.name = "emphasis";
|
||
|
|
||
|
exports.init = function(parser) {
|
||
|
this.parser = parser;
|
||
|
// Regexp to match
|
||
|
this.matchRegExp = /''|\/\/|__|\^\^|,,|~~/mg;
|
||
|
};
|
||
|
|
||
|
exports.parse = function() {
|
||
|
// Move past the match
|
||
|
this.parser.pos = this.matchRegExp.lastIndex;
|
||
|
// Figure out which element and closing regexp to use
|
||
|
var tag,reEnd;
|
||
|
switch(this.match[0]) {
|
||
|
case "''": // Bold
|
||
|
tag = "strong";
|
||
|
reEnd = /''/mg;
|
||
|
break;
|
||
|
case "//": // Italics
|
||
|
tag = "em";
|
||
|
reEnd = /\/\//mg;
|
||
|
break;
|
||
|
case "__": // Underline
|
||
|
tag = "u";
|
||
|
reEnd = /__/mg;
|
||
|
break;
|
||
|
case "^^": // Superscript
|
||
|
tag = "sup";
|
||
|
reEnd = /\^\^/mg;
|
||
|
break;
|
||
|
case ",,": // Subscript
|
||
|
tag = "sub";
|
||
|
reEnd = /,,/mg;
|
||
|
break;
|
||
|
case "~~": // Strikethrough
|
||
|
tag = "strike";
|
||
|
reEnd = /~~/mg;
|
||
|
break;
|
||
|
}
|
||
|
// Parse the run including the terminator
|
||
|
var tree = this.parser.parseRun(reEnd,{eatTerminator: true});
|
||
|
// Return the classed span
|
||
|
return [{
|
||
|
type: "element",
|
||
|
tag: tag,
|
||
|
children: tree
|
||
|
}];
|
||
|
};
|
||
|
|
||
|
})();
|