From 03da553c3bb49076ffb2c52d521f32bffb8b7b5f Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 5 Jun 2012 16:33:35 +0100 Subject: [PATCH] Added wikitext for m- and n-dashes --- .../parsers/newwikitextparser/rules/dash.js | 28 +++++++++++++++++++ readme.md | 2 +- tw5.com/tiddlers/TestingNewWikiText.tid | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 core/modules/parsers/newwikitextparser/rules/dash.js diff --git a/core/modules/parsers/newwikitextparser/rules/dash.js b/core/modules/parsers/newwikitextparser/rules/dash.js new file mode 100644 index 000000000..c863c1ee8 --- /dev/null +++ b/core/modules/parsers/newwikitextparser/rules/dash.js @@ -0,0 +1,28 @@ +/*\ +title: $:/core/modules/parsers/newwikitextparser/rules/dash.js +type: application/javascript +module-type: wikitextrule + +Wiki text run rule for HTML entities + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "dash"; + +exports.runParser = true; + +exports.regExpString = "-{2,3}(?=\\s)"; + +exports.parse = function(match,isBlock) { + this.pos = match.index + match[0].length; + match = /(-{2,3})/mg.exec(match[0]); + var dash = match[0].length === 2 ? "–" : "—"; + return [$tw.Tree.Entity(dash)]; +}; + +})(); diff --git a/readme.md b/readme.md index 3344f07b2..d5d1a011e 100644 --- a/readme.md +++ b/readme.md @@ -12,7 +12,7 @@ store.addTiddler(new Tiddler(storyTiddler,{text: navigateTo + "\n" + s dependentAll: false }

The tiddlers field is a hashmap of the title of each tiddler that is linked or included in the current one. The value is true if the tiddler is a 'fat' dependency (ie the text is included in some way) or false if the tiddler is a skinny dependency.

The dependentAll field is used to indicate that the tiddler contains a macro that scans the entire pool of tiddlers (for example the <<list>> macro), and is potentially dependent on any of them. The effect is that the tiddler should be rerendered whenever any other tiddler changes.

Rendering

The parseTree.compile(type) method returns a renderer object that contains a JavaScript function that generates the new representation of the original parsed text.

The renderer is invoked as follows:

var renderer = parseTree.compile("text/html");
 var html = renderer.render(tiddler,store);
-

The tiddler parameter to the render method identifies the tiddler that is acting as the context for this rendering -- for example, it provides the fields displayed by the <<view>> macro. The store parameter is used to resolve any references to other tiddlers.

Rerendering

When rendering to the HTML/SVG DOM in the browser, TiddlyWiki5 also allows a previous rendering to be selectively updated in response to changes in dependent tiddlers. At the moment, only the WikiTextRenderer supports rerendering.

The rerender method on the renderer is called as follows:

var node = document.getElementById("myNode");
+

The tiddler parameter to the render method identifies the tiddler that is acting as the context for this rendering – for example, it provides the fields displayed by the <<view>> macro. The store parameter is used to resolve any references to other tiddlers.

Rerendering

When rendering to the HTML/SVG DOM in the browser, TiddlyWiki5 also allows a previous rendering to be selectively updated in response to changes in dependent tiddlers. At the moment, only the WikiTextRenderer supports rerendering.

The rerender method on the renderer is called as follows:

var node = document.getElementById("myNode");
 var renderer = parseTree.compile("text/html");
 myNode.innerHTML = renderer.render(tiddler,store);
 // And then, later:
diff --git a/tw5.com/tiddlers/TestingNewWikiText.tid b/tw5.com/tiddlers/TestingNewWikiText.tid
index 00dc0cc4c..dba1a6524 100644
--- a/tw5.com/tiddlers/TestingNewWikiText.tid
+++ b/tw5.com/tiddlers/TestingNewWikiText.tid
@@ -9,6 +9,8 @@ One two three four. With a link to HelloThere. And a link to TiddlyWiki and Tidd
 
 Here's an http link: http://www.google.com/, and a suppressed link: ~http://www.apple.com/.
 
+This is a series -- of dashes --- that are of different ---- sizes!
+
 Here's a paragraph with an embedded macro <> and that was it.
 
 {{{