mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-24 17:10:29 +00:00
Added run parser for emphasis like bold and italics
This commit is contained in:
parent
63ca67e0ea
commit
55dd392fe4
64
core/modules/parsers/newwikitextparser/rules/emphasis.js
Normal file
64
core/modules/parsers/newwikitextparser/rules/emphasis.js
Normal file
@ -0,0 +1,64 @@
|
||||
/*\
|
||||
title: $:/core/modules/parsers/newwikitextparser/rules/emphasis.js
|
||||
type: application/javascript
|
||||
module-type: wikitextrule
|
||||
|
||||
Wiki text run rule for emphasis
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.name = "emphasis";
|
||||
|
||||
exports.runParser = true;
|
||||
|
||||
exports.regExpString = "''|\/\/|__|\\^\\^|~~|--(?!\\s|$)";
|
||||
|
||||
exports.parse = function(match,isBlock) {
|
||||
this.pos = match.index + match[0].length;
|
||||
var el,regExp;
|
||||
switch(match[0]) {
|
||||
case "''": // Bold
|
||||
el = "strong";
|
||||
regExp = /('')|(\r?\n)/mg;
|
||||
break;
|
||||
case "//": // Italics
|
||||
el = "em";
|
||||
regExp = /(\/\/)|(\r?\n)/mg;
|
||||
break;
|
||||
case "__": // Underline
|
||||
el = "u";
|
||||
regExp = /(__)|(\r?\n)/mg;
|
||||
break;
|
||||
case "^^":
|
||||
el = "sup";
|
||||
regExp = /(\^\^)|(\r?\n)/mg;
|
||||
break;
|
||||
case "~~":
|
||||
el = "sub";
|
||||
regExp = /(~~)|(\r?\n)/mg;
|
||||
break;
|
||||
case "--":
|
||||
el = "strike";
|
||||
regExp = /(--)|(\r?\n)/mg;
|
||||
break;
|
||||
}
|
||||
// Parse the run up to the terminator
|
||||
var tree = this.parseRun(regExp,{leaveTerminator: true});
|
||||
// Check for the terminator
|
||||
regExp.lastIndex = this.pos;
|
||||
match = regExp.exec(this.source);
|
||||
if(match && match.index === this.pos) {
|
||||
// Only consume the terminator if it isn't a line break
|
||||
if(match[1]) {
|
||||
this.pos = match.index + match[0].length;
|
||||
}
|
||||
}
|
||||
return [$tw.Tree.Element(el,{},tree)];
|
||||
};
|
||||
|
||||
})();
|
Loading…
Reference in New Issue
Block a user