/* Wikifier for TiddlyWiki format text The wikifier parses wikitext into an intermediate tree from which the HTML is generated. HTML elements are stored in the tree like this: {type: "div", attributes: { attr1: value, style: { name: value, name2: value2 } }, children: [ {child}, {child}, ]} Text nodes are: {type: "text", value: "string of text node"} */ /*global require: false, exports: false, process: false */ "use strict"; var Tiddler = require("./Tiddler.js").Tiddler, TiddlyWiki = require("./TiddlyWiki.js").TiddlyWiki, utils = require("./Utils.js"), util = require("util"); // Construct a wikifier object around a Formatter() object var Wikifier = function(store,formatter) { this.store = store; this.formatter = formatter; this.autoLinkWikiWords = true; }; // Wikify a string as if it were from a particular tiddler and return it as an HTML string Wikifier.prototype.wikify = function(source,tiddler) { this.source = source; this.nextMatch = 0; this.tiddler = tiddler; this.tree = []; this.output = null; this.subWikify(this.tree); return this.tree; // Just return the tree for now }; // Wikify a string as if it were from a particular tiddler and return it as plain text Wikifier.prototype.wikifyPlain = function(source,tiddler) { this.source = source; this.nextMatch = 0; this.tiddler = tiddler; this.tree = []; this.output = null; this.subWikify(this.tree); var resultText = [], extractText = function(tree) { for(var t=0; t this.nextMatch) this.outputText(this.output,this.nextMatch,formatterMatch.index); // Set the match parameters for the handler this.matchStart = formatterMatch.index; this.matchLength = formatterMatch[0].length; this.matchText = formatterMatch[0]; this.nextMatch = this.formatter.formatterRegExp.lastIndex; // Figure out which formatter matched and call its handler var t; for(t=1; t this.nextMatch) this.outputText(this.output,this.nextMatch,terminatorMatch.index); // Set the match parameters this.matchText = terminatorMatch[1]; this.matchLength = terminatorMatch[1].length; this.matchStart = terminatorMatch.index; this.nextMatch = this.matchStart + this.matchLength; // Restore the output pointer this.output = oldOutput; return; } // It must be a formatter match; output any text before the match if(formatterMatch.index > this.nextMatch) this.outputText(this.output,this.nextMatch,formatterMatch.index); // Set the match parameters this.matchStart = formatterMatch.index; this.matchLength = formatterMatch[0].length; this.matchText = formatterMatch[0]; this.nextMatch = this.formatter.formatterRegExp.lastIndex; // Figure out which formatter matched and call its handler var t; for(t=1; t