diff --git a/js/Wikifier.js b/js/Wikifier.js index ad574e926..b44304f71 100755 --- a/js/Wikifier.js +++ b/js/Wikifier.js @@ -2,10 +2,10 @@ Wikifier for TiddlyWiki format text -The wikifier parses wikitext into an intermediate tree from which the HTML is generated. The tree -looks like this: +The wikifier parses wikitext into an intermediate tree from which the HTML is generated. + +HTML elements are stored in the tree like this: -this.tree = [ {type: "div", attributes: { attr1: value, attr2: value @@ -13,7 +13,10 @@ this.tree = [ {child}, {child}, ]} -]; + +Text nodes are: + + {type: "text", value: "string of text node"} */ @@ -25,29 +28,51 @@ var Tiddler = require("./Tiddler.js").Tiddler, utils = require("./Utils.js"), util = require("util"); -// Construct a wikifier object -// source - source string that's going to be wikified -// formatter - Formatter() object containing the list of formatters to be used -// tiddler - reference to the tiddler that's taken to be the container for this wikification -var Wikifier = function(source,formatter,tiddler) -{ - this.source = source; - this.output = null; +// Construct a wikifier object around a Formatter() object +var Wikifier = function(formatter) { this.formatter = formatter; - this.nextMatch = 0; this.autoLinkWikiWords = true; - this.isStatic = false; - this.tiddler = tiddler; -} +}; -Wikifier.prototype.wikifyPlain = function() +// 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 0) - text = text.substr(0,limit); - var wikifier = new Wikifier(text,formatter,null,tiddler); - return wikifier.wikifyPlain(); -}; - exports.Wikifier = Wikifier;