1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-23 15:36:52 +00:00

Text-slicer: Add primitive support for escaping wikitext

This commit is contained in:
Jermolene 2018-01-04 16:02:18 +00:00
parent de4eb5ca89
commit a7a3748bca

View File

@ -31,6 +31,7 @@ function Slicer(options) {
this.wiki = options.wiki; this.wiki = options.wiki;
this.role = options.role || "sliced-html"; this.role = options.role || "sliced-html";
this.outputMode = options.outputMode || "html"; this.outputMode = options.outputMode || "html";
this.escapeWikiText = options.escapeWikiText || false;
this.callbackFn = options.callback; this.callbackFn = options.callback;
// Get the slicer rules // Get the slicer rules
var nameSlicerRules = null; var nameSlicerRules = null;
@ -337,7 +338,18 @@ Slicer.prototype.onCloseTag = function(name) {
}; };
Slicer.prototype.onText = function(text) { Slicer.prototype.onText = function(text) {
this.addTextToCurrentChunk($tw.utils.htmlEncode(text)); var self = this;
text = $tw.utils.htmlEncode(text);
// Optionally escape common character sequences that might be parsed as wikitext
if(this.escapeWikiText) {
$tw.utils.each(["[[","{{","__","''","//",",,","^^","~~","`","--","\"\"","@@"],function(str) {
var replace = str.split("").map(function(c) {
return "&#" + c.charCodeAt(0) + ";";
}).join("");
text = text.replace(new RegExp($tw.utils.escapeRegExp(str),"mg"),replace);
});
}
this.addTextToCurrentChunk(text);
this.addTextToCurrentChunk(text,"title"); this.addTextToCurrentChunk(text,"title");
}; };