tweecode/twine — pull request #119 by mthuurne (2014-02-05 10:07:06+00:00)
Title: Add StoryInit feature

See this discussion thread: http://twinery.org/forum/index.php/topic,1412.0.html

Please carefully review the JavaScript part of the changes. I didn't find any problems while testing, but I only tested the new functionality, so regressions in old functionality could exist. In particular:

I'm passing "null" for the output element and I changed "throwError" to show an alert box if there is no element to attach the error message to. Previously errors would be ignored if the element was null. In general I think it is better to complain loudly on errors instead of hiding them, but I don't know if there is maybe some existing code that relies on the errors being suppressed.

Passing "null" as the output doesn't cause any problems, since Wikifier's outputText() is not called when processing a full string. However, I don't know whether that is something that can be safely relied on, or something that might change in the future.

I had this in an earlier version; it is a bit more defensive, but maybe unnecessarily so:

if (tale.has("StoryInit")) {
function InitWikifier(source) {
this.outputText = function (place, startPos, endPos) { };
Wikifier.call(this, null, source);
}
InitWikifier.prototype = Wikifier.prototype;
new InitWikifier(tale.get("StoryInit").text);
}