From 2ec58f7fa223f250843eaa5f21d6a938617cc612 Mon Sep 17 00:00:00 2001 From: Stephan Hradek Date: Sun, 1 Dec 2013 21:21:15 +0100 Subject: [PATCH 1/4] added quote rules --- .../modules/parsers/wikiparser/rules/quote.js | 98 +++++++++++++++++++ .../parsers/wikiparser/rules/quoteblock.js | 96 ++++++++++++++++++ 2 files changed, 194 insertions(+) create mode 100644 core/modules/parsers/wikiparser/rules/quote.js create mode 100644 core/modules/parsers/wikiparser/rules/quoteblock.js diff --git a/core/modules/parsers/wikiparser/rules/quote.js b/core/modules/parsers/wikiparser/rules/quote.js new file mode 100644 index 000000000..393259a78 --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/quote.js @@ -0,0 +1,98 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/quote.js +type: application/javascript +module-type: wikirule + +Wiki text block rule for quotes. For example: + +``` +> This is aquote +> It has two paragraphs + +> This is another quite +>> This is a quoted quote +> And another paragraph +``` + +A CSS class can be applied to a quote item as follows: + +``` +> First quoted paragraph +>.active Second prargraph has the class `active` +> Third quoted paragraph +``` + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "quote"; +exports.types = {block: true}; + +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /(>+)/mg; +}; + +var quoteInfo = {quoteTag: "blockquote", paraTag: "p", attributes: { class: { type: "string", value:"tw-quote" }}}; + +/* +Parse the most recent match +*/ +exports.parse = function() { + // Array of parse tree nodes for the previous row of the quote + var quoteStack = []; + // Cycle through the items in the quote + while(true) { + // Match the list marker + var reMatch = /(>+)/mg; + reMatch.lastIndex = this.parser.pos; + var match = reMatch.exec(this.parser.source); + if(!match || match.index !== this.parser.pos) { + break; + } + // Move past the quote marker + this.parser.pos = match.index + match[0].length; + // Walk through the quote markers for the current row + for(var t=0; t match[0].length) { + quoteStack.splice(match[0].length,quoteStack.length - match[0].length); + } + // Process the body of the list item into the last list item + var lastQuoteChildren = quoteStack[quoteStack.length-1].children, + lastQuoteItem = lastQuoteChildren[lastQuoteChildren.length-1], + classes = this.parser.parseClasses(); + this.parser.skipWhitespace({treatNewlinesAsNonWhitespace: true}); + var tree = this.parser.parseInlineRun(/(\r?\n)/mg); + lastQuoteItem.children.push.apply(lastQuoteItem.children,tree); + if(classes.length > 0) { + $tw.utils.addClassToParseTreeNode(lastQuoteItem,classes.join(" ")); + } + // Consume any whitespace following the list item + this.parser.skipWhitespace(); + } + // Return the root element of the list + return [quoteStack[0]]; +}; + +})(); diff --git a/core/modules/parsers/wikiparser/rules/quoteblock.js b/core/modules/parsers/wikiparser/rules/quoteblock.js new file mode 100644 index 000000000..b3a0c8ae6 --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/quoteblock.js @@ -0,0 +1,96 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/quoteblock.js +type: application/javascript +module-type: wikirule + +Wiki text rule for quote blocks. For example: + +``` + <<<.optionalClass(es) optional cited from + a quote + <<< + + <<<.optionalClass(es) + a quote + <<< optional cited from +``` + +Quotes can be quoted by putting more 0 ) { + tree.unshift({ + type: "element", + tag: "cite", + children: cite + }); + } + + // Move past the 0 ) { + tree.push({ + type: "element", + tag: "cite", + children: cite + }); + } + + // Return the blockquote element + return [{ + type: "element", + tag: "blockquote", + attributes: { + class: { type: "string", value: classes.join(" ") }, + }, + children: tree + }]; +}; + +})(); From 8ed364ed72f6f7d1ff391a32043222877a29c47d Mon Sep 17 00:00:00 2001 From: Stephan Hradek Date: Sun, 1 Dec 2013 22:01:21 +0100 Subject: [PATCH 2/4] fixed a small bug related to closing wiki-tag --- core/modules/parsers/wikiparser/rules/quoteblock.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/modules/parsers/wikiparser/rules/quoteblock.js b/core/modules/parsers/wikiparser/rules/quoteblock.js index b3a0c8ae6..9c943bd0a 100644 --- a/core/modules/parsers/wikiparser/rules/quoteblock.js +++ b/core/modules/parsers/wikiparser/rules/quoteblock.js @@ -69,10 +69,9 @@ exports.parse = function() { // Move past the 0 ) { tree.push({ From 62b9fb336bbb878f44500dbf3a2fa7ed7325f104 Mon Sep 17 00:00:00 2001 From: Stephan Hradek Date: Sun, 1 Dec 2013 22:05:49 +0100 Subject: [PATCH 3/4] fixed a small bug related to closing wiki-tag - no really --- core/modules/parsers/wikiparser/rules/quoteblock.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/modules/parsers/wikiparser/rules/quoteblock.js b/core/modules/parsers/wikiparser/rules/quoteblock.js index 9c943bd0a..e69c8edc8 100644 --- a/core/modules/parsers/wikiparser/rules/quoteblock.js +++ b/core/modules/parsers/wikiparser/rules/quoteblock.js @@ -67,8 +67,6 @@ exports.parse = function() { }); } - // Move past the Date: Fri, 6 Dec 2013 09:57:56 +0100 Subject: [PATCH 4/4] as requested - quote.js removed because of quotelist - do not forget to add some css classes --- .../modules/parsers/wikiparser/rules/quote.js | 98 ------------------- 1 file changed, 98 deletions(-) delete mode 100644 core/modules/parsers/wikiparser/rules/quote.js diff --git a/core/modules/parsers/wikiparser/rules/quote.js b/core/modules/parsers/wikiparser/rules/quote.js deleted file mode 100644 index 393259a78..000000000 --- a/core/modules/parsers/wikiparser/rules/quote.js +++ /dev/null @@ -1,98 +0,0 @@ -/*\ -title: $:/core/modules/parsers/wikiparser/rules/quote.js -type: application/javascript -module-type: wikirule - -Wiki text block rule for quotes. For example: - -``` -> This is aquote -> It has two paragraphs - -> This is another quite ->> This is a quoted quote -> And another paragraph -``` - -A CSS class can be applied to a quote item as follows: - -``` -> First quoted paragraph ->.active Second prargraph has the class `active` -> Third quoted paragraph -``` - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -exports.name = "quote"; -exports.types = {block: true}; - -exports.init = function(parser) { - this.parser = parser; - // Regexp to match - this.matchRegExp = /(>+)/mg; -}; - -var quoteInfo = {quoteTag: "blockquote", paraTag: "p", attributes: { class: { type: "string", value:"tw-quote" }}}; - -/* -Parse the most recent match -*/ -exports.parse = function() { - // Array of parse tree nodes for the previous row of the quote - var quoteStack = []; - // Cycle through the items in the quote - while(true) { - // Match the list marker - var reMatch = /(>+)/mg; - reMatch.lastIndex = this.parser.pos; - var match = reMatch.exec(this.parser.source); - if(!match || match.index !== this.parser.pos) { - break; - } - // Move past the quote marker - this.parser.pos = match.index + match[0].length; - // Walk through the quote markers for the current row - for(var t=0; t match[0].length) { - quoteStack.splice(match[0].length,quoteStack.length - match[0].length); - } - // Process the body of the list item into the last list item - var lastQuoteChildren = quoteStack[quoteStack.length-1].children, - lastQuoteItem = lastQuoteChildren[lastQuoteChildren.length-1], - classes = this.parser.parseClasses(); - this.parser.skipWhitespace({treatNewlinesAsNonWhitespace: true}); - var tree = this.parser.parseInlineRun(/(\r?\n)/mg); - lastQuoteItem.children.push.apply(lastQuoteItem.children,tree); - if(classes.length > 0) { - $tw.utils.addClassToParseTreeNode(lastQuoteItem,classes.join(" ")); - } - // Consume any whitespace following the list item - this.parser.skipWhitespace(); - } - // Return the root element of the list - return [quoteStack[0]]; -}; - -})();