From 7aa6c7c06d8b5359f183e6b9f6f57cf89611cda8 Mon Sep 17 00:00:00 2001 From: Mario Pietsch Date: Thu, 24 Jul 2014 17:43:03 +0200 Subject: [PATCH 1/4] splited emphasis.js into several modules to have fine grained control with wikification rules eg: rules except bold ... This fixes #701 --- .../parsers/wikiparser/rules/emphasis.js | 79 ------------------- .../parsers/wikiparser/rules/emphasis/bold.js | 50 ++++++++++++ .../wikiparser/rules/emphasis/italic.js | 50 ++++++++++++ .../rules/emphasis/stricethrough.js | 50 ++++++++++++ .../wikiparser/rules/emphasis/subscript.js | 50 ++++++++++++ .../wikiparser/rules/emphasis/superscript.js | 50 ++++++++++++ .../wikiparser/rules/emphasis/underscore.js | 50 ++++++++++++ 7 files changed, 300 insertions(+), 79 deletions(-) delete mode 100644 core/modules/parsers/wikiparser/rules/emphasis.js create mode 100644 core/modules/parsers/wikiparser/rules/emphasis/bold.js create mode 100644 core/modules/parsers/wikiparser/rules/emphasis/italic.js create mode 100644 core/modules/parsers/wikiparser/rules/emphasis/stricethrough.js create mode 100644 core/modules/parsers/wikiparser/rules/emphasis/subscript.js create mode 100644 core/modules/parsers/wikiparser/rules/emphasis/superscript.js create mode 100644 core/modules/parsers/wikiparser/rules/emphasis/underscore.js diff --git a/core/modules/parsers/wikiparser/rules/emphasis.js b/core/modules/parsers/wikiparser/rules/emphasis.js deleted file mode 100644 index 5950efbbe..000000000 --- a/core/modules/parsers/wikiparser/rules/emphasis.js +++ /dev/null @@ -1,79 +0,0 @@ -/*\ -title: $:/core/modules/parsers/wikiparser/rules/emphasis.js -type: application/javascript -module-type: wikirule - -Wiki text inline rule for emphasis. For example: - -``` - This is ''bold'' text - - This is //italic// text - - This is __underlined__ text - - This is ^^superscript^^ text - - This is ,,subscript,, text - - This is ~~strikethrough~~ text -``` - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -exports.name = "emphasis"; -exports.types = {inline: true}; - -exports.init = function(parser) { - this.parser = parser; - // Regexp to match - this.matchRegExp = /''|\/\/|__|\^\^|,,|~~/mg; -}; - -exports.parse = function() { - // Move past the match - this.parser.pos = this.matchRegExp.lastIndex; - // Figure out which element and closing regexp to use - var tag,reEnd; - switch(this.match[0]) { - case "''": // Bold - tag = "strong"; - reEnd = /''/mg; - break; - case "//": // Italics - tag = "em"; - reEnd = /\/\//mg; - break; - case "__": // Underline - tag = "u"; - reEnd = /__/mg; - break; - case "^^": // Superscript - tag = "sup"; - reEnd = /\^\^/mg; - break; - case ",,": // Subscript - tag = "sub"; - reEnd = /,,/mg; - break; - case "~~": // Strikethrough - tag = "strike"; - reEnd = /~~/mg; - break; - } - // Parse the run including the terminator - var tree = this.parser.parseInlineRun(reEnd,{eatTerminator: true}); - // Return the classed span - return [{ - type: "element", - tag: tag, - children: tree - }]; -}; - -})(); diff --git a/core/modules/parsers/wikiparser/rules/emphasis/bold.js b/core/modules/parsers/wikiparser/rules/emphasis/bold.js new file mode 100644 index 000000000..127b84579 --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/emphasis/bold.js @@ -0,0 +1,50 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/emphasis/bold.js +type: application/javascript +module-type: wikirule + +Wiki text inline rule for emphasis - bold. For example: + +``` + This is ''bold'' text +``` + +This wikiparser can be modified using the rules eg: + +``` +\rules except bold +\rules only bold +``` + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "bold"; +exports.types = {inline: true}; + +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /''/mg; +}; + +exports.parse = function() { + // Move past the match + this.parser.pos = this.matchRegExp.lastIndex; + + // Parse the run including the terminator + var tree = this.parser.parseInlineRun(/''/mg,{eatTerminator: true}); + + // Return the classed span + return [{ + type: "element", + tag: "strong", + children: tree + }]; +}; + +})(); \ No newline at end of file diff --git a/core/modules/parsers/wikiparser/rules/emphasis/italic.js b/core/modules/parsers/wikiparser/rules/emphasis/italic.js new file mode 100644 index 000000000..20fccd342 --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/emphasis/italic.js @@ -0,0 +1,50 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/emphasis/italic.js +type: application/javascript +module-type: wikirule + +Wiki text inline rule for emphasis - italic. For example: + +``` + This is //italic// text +``` + +This wikiparser can be modified using the rules eg: + +``` +\rules except italic +\rules only italic +``` + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "italic"; +exports.types = {inline: true}; + +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /\/\//mg; +}; + +exports.parse = function() { + // Move past the match + this.parser.pos = this.matchRegExp.lastIndex; + + // Parse the run including the terminator + var tree = this.parser.parseInlineRun(/\/\//mg,{eatTerminator: true}); + + // Return the classed span + return [{ + type: "element", + tag: "em", + children: tree + }]; +}; + +})(); \ No newline at end of file diff --git a/core/modules/parsers/wikiparser/rules/emphasis/stricethrough.js b/core/modules/parsers/wikiparser/rules/emphasis/stricethrough.js new file mode 100644 index 000000000..7b272bd0c --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/emphasis/stricethrough.js @@ -0,0 +1,50 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/emphasis/strikethrough.js +type: application/javascript +module-type: wikirule + +Wiki text inline rule for emphasis - strikethrough. For example: + +``` + This is ~~strikethrough~~ text +``` + +This wikiparser can be modified using the rules eg: + +``` +\rules except strikethrough +\rules only strikethrough +``` + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "strikethrough"; +exports.types = {inline: true}; + +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /~~/mg; +}; + +exports.parse = function() { + // Move past the match + this.parser.pos = this.matchRegExp.lastIndex; + + // Parse the run including the terminator + var tree = this.parser.parseInlineRun(/~~/mg,{eatTerminator: true}); + + // Return the classed span + return [{ + type: "element", + tag: "strike", + children: tree + }]; +}; + +})(); diff --git a/core/modules/parsers/wikiparser/rules/emphasis/subscript.js b/core/modules/parsers/wikiparser/rules/emphasis/subscript.js new file mode 100644 index 000000000..c4f57bd4b --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/emphasis/subscript.js @@ -0,0 +1,50 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/emphasis/subscript.js +type: application/javascript +module-type: wikirule + +Wiki text inline rule for emphasis - subscript. For example: + +``` + This is ,,subscript,, text +``` + +This wikiparser can be modified using the rules eg: + +``` +\rules except subscript +\rules only subscript +``` + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "subscript"; +exports.types = {inline: true}; + +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /,,/mg; +}; + +exports.parse = function() { + // Move past the match + this.parser.pos = this.matchRegExp.lastIndex; + + // Parse the run including the terminator + var tree = this.parser.parseInlineRun(/,,/mg,{eatTerminator: true}); + + // Return the classed span + return [{ + type: "element", + tag: "sub", + children: tree + }]; +}; + +})(); diff --git a/core/modules/parsers/wikiparser/rules/emphasis/superscript.js b/core/modules/parsers/wikiparser/rules/emphasis/superscript.js new file mode 100644 index 000000000..09a1e8ed1 --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/emphasis/superscript.js @@ -0,0 +1,50 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/emphasis/superscript.js +type: application/javascript +module-type: wikirule + +Wiki text inline rule for emphasis - superscript. For example: + +``` + This is ^^superscript^^ text +``` + +This wikiparser can be modified using the rules eg: + +``` +\rules except superscript +\rules only superscript +``` + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "superscript"; +exports.types = {inline: true}; + +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /\^\^/mg; +}; + +exports.parse = function() { + // Move past the match + this.parser.pos = this.matchRegExp.lastIndex; + + // Parse the run including the terminator + var tree = this.parser.parseInlineRun(/\^\^/mg,{eatTerminator: true}); + + // Return the classed span + return [{ + type: "element", + tag: "sup", + children: tree + }]; +}; + +})(); \ No newline at end of file diff --git a/core/modules/parsers/wikiparser/rules/emphasis/underscore.js b/core/modules/parsers/wikiparser/rules/emphasis/underscore.js new file mode 100644 index 000000000..529c6524b --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/emphasis/underscore.js @@ -0,0 +1,50 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/emphasis/underscore.js +type: application/javascript +module-type: wikirule + +Wiki text inline rule for emphasis - underscore. For example: + +``` + This is __underscore__ text +``` + +This wikiparser can be modified using the rules eg: + +``` +\rules except underscore +\rules only underscore +``` + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "underscore"; +exports.types = {inline: true}; + +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /__/mg; +}; + +exports.parse = function() { + // Move past the match + this.parser.pos = this.matchRegExp.lastIndex; + + // Parse the run including the terminator + var tree = this.parser.parseInlineRun(/__/mg,{eatTerminator: true}); + + // Return the classed span + return [{ + type: "element", + tag: "u", + children: tree + }]; +}; + +})(); \ No newline at end of file From 95f6c921922eb43c4f6de8c6d8a1115b9da3453c Mon Sep 17 00:00:00 2001 From: Mario Pietsch Date: Thu, 24 Jul 2014 23:47:13 +0200 Subject: [PATCH 2/4] fixed whitespace --- core/modules/parsers/wikiparser/rules/emphasis/bold.js | 4 ++-- core/modules/parsers/wikiparser/rules/emphasis/italic.js | 4 ++-- .../parsers/wikiparser/rules/emphasis/stricethrough.js | 2 +- core/modules/parsers/wikiparser/rules/emphasis/subscript.js | 4 ++-- core/modules/parsers/wikiparser/rules/emphasis/superscript.js | 4 ++-- core/modules/parsers/wikiparser/rules/emphasis/underscore.js | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/modules/parsers/wikiparser/rules/emphasis/bold.js b/core/modules/parsers/wikiparser/rules/emphasis/bold.js index 127b84579..3799feeb5 100644 --- a/core/modules/parsers/wikiparser/rules/emphasis/bold.js +++ b/core/modules/parsers/wikiparser/rules/emphasis/bold.js @@ -36,10 +36,10 @@ exports.parse = function() { // Move past the match this.parser.pos = this.matchRegExp.lastIndex; - // Parse the run including the terminator + // Parse the run including the terminator var tree = this.parser.parseInlineRun(/''/mg,{eatTerminator: true}); - // Return the classed span + // Return the classed span return [{ type: "element", tag: "strong", diff --git a/core/modules/parsers/wikiparser/rules/emphasis/italic.js b/core/modules/parsers/wikiparser/rules/emphasis/italic.js index 20fccd342..3e0744c4d 100644 --- a/core/modules/parsers/wikiparser/rules/emphasis/italic.js +++ b/core/modules/parsers/wikiparser/rules/emphasis/italic.js @@ -36,10 +36,10 @@ exports.parse = function() { // Move past the match this.parser.pos = this.matchRegExp.lastIndex; - // Parse the run including the terminator + // Parse the run including the terminator var tree = this.parser.parseInlineRun(/\/\//mg,{eatTerminator: true}); - // Return the classed span + // Return the classed span return [{ type: "element", tag: "em", diff --git a/core/modules/parsers/wikiparser/rules/emphasis/stricethrough.js b/core/modules/parsers/wikiparser/rules/emphasis/stricethrough.js index 7b272bd0c..af722b140 100644 --- a/core/modules/parsers/wikiparser/rules/emphasis/stricethrough.js +++ b/core/modules/parsers/wikiparser/rules/emphasis/stricethrough.js @@ -39,7 +39,7 @@ exports.parse = function() { // Parse the run including the terminator var tree = this.parser.parseInlineRun(/~~/mg,{eatTerminator: true}); - // Return the classed span + // Return the classed span return [{ type: "element", tag: "strike", diff --git a/core/modules/parsers/wikiparser/rules/emphasis/subscript.js b/core/modules/parsers/wikiparser/rules/emphasis/subscript.js index c4f57bd4b..12be0fbbc 100644 --- a/core/modules/parsers/wikiparser/rules/emphasis/subscript.js +++ b/core/modules/parsers/wikiparser/rules/emphasis/subscript.js @@ -36,10 +36,10 @@ exports.parse = function() { // Move past the match this.parser.pos = this.matchRegExp.lastIndex; - // Parse the run including the terminator + // Parse the run including the terminator var tree = this.parser.parseInlineRun(/,,/mg,{eatTerminator: true}); - // Return the classed span + // Return the classed span return [{ type: "element", tag: "sub", diff --git a/core/modules/parsers/wikiparser/rules/emphasis/superscript.js b/core/modules/parsers/wikiparser/rules/emphasis/superscript.js index 09a1e8ed1..5a5330d8c 100644 --- a/core/modules/parsers/wikiparser/rules/emphasis/superscript.js +++ b/core/modules/parsers/wikiparser/rules/emphasis/superscript.js @@ -36,10 +36,10 @@ exports.parse = function() { // Move past the match this.parser.pos = this.matchRegExp.lastIndex; - // Parse the run including the terminator + // Parse the run including the terminator var tree = this.parser.parseInlineRun(/\^\^/mg,{eatTerminator: true}); - // Return the classed span + // Return the classed span return [{ type: "element", tag: "sup", diff --git a/core/modules/parsers/wikiparser/rules/emphasis/underscore.js b/core/modules/parsers/wikiparser/rules/emphasis/underscore.js index 529c6524b..d36bd242d 100644 --- a/core/modules/parsers/wikiparser/rules/emphasis/underscore.js +++ b/core/modules/parsers/wikiparser/rules/emphasis/underscore.js @@ -36,10 +36,10 @@ exports.parse = function() { // Move past the match this.parser.pos = this.matchRegExp.lastIndex; - // Parse the run including the terminator + // Parse the run including the terminator var tree = this.parser.parseInlineRun(/__/mg,{eatTerminator: true}); - // Return the classed span + // Return the classed span return [{ type: "element", tag: "u", From bb47f1dbadadbbf8a5cea8f9dad11f98771ecf56 Mon Sep 17 00:00:00 2001 From: Mario Pietsch Date: Thu, 24 Jul 2014 23:49:42 +0200 Subject: [PATCH 3/4] fix whitespace and filename --- .../rules/emphasis/strikethrough.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 core/modules/parsers/wikiparser/rules/emphasis/strikethrough.js diff --git a/core/modules/parsers/wikiparser/rules/emphasis/strikethrough.js b/core/modules/parsers/wikiparser/rules/emphasis/strikethrough.js new file mode 100644 index 000000000..0fb34fc52 --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/emphasis/strikethrough.js @@ -0,0 +1,50 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/emphasis/strikethrough.js +type: application/javascript +module-type: wikirule + +Wiki text inline rule for emphasis - strikethrough. For example: + +``` + This is ~~strikethrough~~ text +``` + +This wikiparser can be modified using the rules eg: + +``` +\rules except strikethrough +\rules only strikethrough +``` + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.name = "strikethrough"; +exports.types = {inline: true}; + +exports.init = function(parser) { + this.parser = parser; + // Regexp to match + this.matchRegExp = /~~/mg; +}; + +exports.parse = function() { + // Move past the match + this.parser.pos = this.matchRegExp.lastIndex; + + // Parse the run including the terminator + var tree = this.parser.parseInlineRun(/~~/mg,{eatTerminator: true}); + + // Return the classed span + return [{ + type: "element", + tag: "strike", + children: tree + }]; +}; + +})(); From 6de453d796ac5bfa04344730406431d7818442f0 Mon Sep 17 00:00:00 2001 From: Mario Pietsch Date: Thu, 24 Jul 2014 23:51:37 +0200 Subject: [PATCH 4/4] remove stricethrough.js --- .../rules/emphasis/stricethrough.js | 50 ------------------- 1 file changed, 50 deletions(-) delete mode 100644 core/modules/parsers/wikiparser/rules/emphasis/stricethrough.js diff --git a/core/modules/parsers/wikiparser/rules/emphasis/stricethrough.js b/core/modules/parsers/wikiparser/rules/emphasis/stricethrough.js deleted file mode 100644 index af722b140..000000000 --- a/core/modules/parsers/wikiparser/rules/emphasis/stricethrough.js +++ /dev/null @@ -1,50 +0,0 @@ -/*\ -title: $:/core/modules/parsers/wikiparser/rules/emphasis/strikethrough.js -type: application/javascript -module-type: wikirule - -Wiki text inline rule for emphasis - strikethrough. For example: - -``` - This is ~~strikethrough~~ text -``` - -This wikiparser can be modified using the rules eg: - -``` -\rules except strikethrough -\rules only strikethrough -``` - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -exports.name = "strikethrough"; -exports.types = {inline: true}; - -exports.init = function(parser) { - this.parser = parser; - // Regexp to match - this.matchRegExp = /~~/mg; -}; - -exports.parse = function() { - // Move past the match - this.parser.pos = this.matchRegExp.lastIndex; - - // Parse the run including the terminator - var tree = this.parser.parseInlineRun(/~~/mg,{eatTerminator: true}); - - // Return the classed span - return [{ - type: "element", - tag: "strike", - children: tree - }]; -}; - -})();