Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

break up the style regex into 3 sub groups

Because I need to test that the beginning and ending number of quotes
are exactly the same I broke up the style regex into 3 groups for each
type.  Within each test I now also allow for a single quote to pass
through using the `[^']+'[^']+|[^']` syntax that looks for
non-quote+one-quote+non-quote text or all non-quote text.
  • Loading branch information...
commit 345732b8d9f99745753e78c250ca86917f02ca0f 1 parent 172801c
@clarkbw clarkbw authored
Showing with 14 additions and 12 deletions.
  1. +14 −12 lib/converter/wikiToHTMLConverter.js
View
26 lib/converter/wikiToHTMLConverter.js
@@ -1,6 +1,8 @@
var constants = require("./../constants/wikiConstants");
-var STYLE_REGEX = /[']+\s*([^']*)\s*[']+/g;
+var STRONG_EM_STYLE_REGEX = /[']{5}\s*([^']+'[^']+|[^']*)\s*[']{5}/g;
+var STRONG_STYLE_REGEX = /[']{3}\s*([^']+'[^']+|[^']*)\s*[']{3}/g;
+var EM_STYLE_REGEX = /[']{2}\s*([^']+'[^']+|[^']*)\s*[']{2}/g;
var HEADING_REGEX = /^=+([^=]*).*$/g;
var SINGLE_BRACKET_LINK_REGEX = /\[([^\]]*)\]/g;
var LINK_REGEX = /\[\[([^\]]*)\]\]/g;
@@ -93,18 +95,18 @@ function convertLineToHTML(line) {
return "<" + headingTag + ">" + match.substring(index, lastIndex) + "</" + headingTag + ">";
});
+ // cascading order of quote matching such that we don't match a lesser number
+ // of quotes inside a larger number
+ line = line.replace(STRONG_EM_STYLE_REGEX, function (match, subMatch1) {
+ return "<strong><em>" + subMatch1 + "</em></strong>";
+ });
- line = line.replace(STYLE_REGEX, function (match, subMatch1) {
- var index = match.indexOf(subMatch1);
- if (index === 2) {
- return "<em>" + subMatch1 + "</em>";
- } else if (index === 3) {
- return "<strong>" + subMatch1 + "</strong>";
- } else if (index === 5) {
- return "<strong><em>" + subMatch1 + "</em></strong>";
- } else {
- return subMatch1;
- }
+ line = line.replace(STRONG_STYLE_REGEX, function (match, subMatch1) {
+ return "<strong>" + subMatch1 + "</strong>";
+ });
+
+ line = line.replace(EM_STYLE_REGEX, function (match, subMatch1) {
+ return "<em>" + subMatch1 + "</em>";
});
line = line.replace(LINK_REGEX, function (match, matchedLink) {
Please sign in to comment.
Something went wrong with that request. Please try again.