From ec933eb1b550e426ed7a09d5daac60537aa7ce27 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sat, 2 Jun 2012 10:15:52 +0100 Subject: [PATCH] Completed code blocks and runs --- .../newwikitextparser/rules/codeblock.js | 13 +++++++++++- .../newwikitextparser/rules/coderun.js | 20 +++++++++++++++++-- tw5.com/tiddlers/TestingNewWikiText.tid | 2 +- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/core/modules/parsers/newwikitextparser/rules/codeblock.js b/core/modules/parsers/newwikitextparser/rules/codeblock.js index 480349f05..be71dec46 100644 --- a/core/modules/parsers/newwikitextparser/rules/codeblock.js +++ b/core/modules/parsers/newwikitextparser/rules/codeblock.js @@ -20,7 +20,18 @@ exports.regExpString = "\\{\\{\\{\\s*\\r?\\n"; exports.parse = function(match,isBlock) { this.pos = match.index + match[0].length; - return [$tw.Tree.Element("pre",{},this.parseRun(/(\}\}\})/mg))]; + var regExp = /(\r?\n\}\}\})/mg, + text; + regExp.lastIndex = this.pos; + match = regExp.exec(this.source); + if(match) { + text = this.source.substring(this.pos,match.index); + this.pos = match.index + match[0].length; + } else { + text = this.source.substr(this.pos); + this.pos = this.sourceLength; + } + return [$tw.Tree.Element("code",{},[$tw.Tree.Text(text)])]; }; })(); diff --git a/core/modules/parsers/newwikitextparser/rules/coderun.js b/core/modules/parsers/newwikitextparser/rules/coderun.js index 37095e743..1c0694973 100644 --- a/core/modules/parsers/newwikitextparser/rules/coderun.js +++ b/core/modules/parsers/newwikitextparser/rules/coderun.js @@ -16,11 +16,27 @@ exports.name = "coderun"; exports.runParser = true; -exports.regExpString = "\\{\\{\\{"; +exports.regExpString = "(?:\\{\\{\\{)|(?:`)"; exports.parse = function(match,isBlock) { this.pos = match.index + match[0].length; - return [$tw.Tree.Element("code",{},this.parseRun(/(\}\}\})/mg))]; + var regExp, + text; + if(match[0] === "{{{") { + regExp = /(\}\}\})/mg; + } else { + regExp = /(`)/mg; + } + regExp.lastIndex = this.pos; + match = regExp.exec(this.source); + if(match) { + text = this.source.substring(this.pos,match.index); + this.pos = match.index + match[0].length; + } else { + text = this.source.substr(this.pos); + this.pos = this.sourceLength; + } + return [$tw.Tree.Element("code",{},[$tw.Tree.Text(text)])]; }; })(); diff --git a/tw5.com/tiddlers/TestingNewWikiText.tid b/tw5.com/tiddlers/TestingNewWikiText.tid index 37ea80643..82844bbff 100644 --- a/tw5.com/tiddlers/TestingNewWikiText.tid +++ b/tw5.com/tiddlers/TestingNewWikiText.tid @@ -13,7 +13,7 @@ Here's a paragraph with an embedded macro <> and that This will be mono }}} -And this will be {{{inline and monospaced}}}. +And this will be {{{inline and monospaced}}} and `so will this` little bit. Here is a macro <>