Skip to content

Commit

Permalink
Merge pull request #7 from clarkbw/single-quote-titles
Browse files Browse the repository at this point in the history
Single quote titles
  • Loading branch information
Kenshiro committed Jul 27, 2013
2 parents bcf6b8a + 345732b commit ed61508
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/converter/wikiToHTMLConverter.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions test/wikiClientTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ vows.describe("Wikipedia search checks").addBatch({
expect(err).to.be(null);
expect(_(response).startsWith("<p><strong>Albert Einstein</strong>")).to.be(true);
// console.log(response);
// console.log("*************************************************************************************\n\n\n\n");
},
},
"When searching (in html) for a wiki article with a single quote in the title":{
topic: function(){
var options = {query: "Harry Potter and the Philosopher's Stone", format: "html"};
wikiClient.searchArticle(options, this.callback);
},

"A valid full article is returned": function(err, response){
expect(err).to.be(null);
expect(_(response).startsWith("<p><strong><em>Harry Potter and the Philosopher's Stone</em></strong>")).to.be(true);
// console.log(response);
// console.log("*************************************************************************************\n\n\n\n");
}
},
Expand Down

0 comments on commit ed61508

Please sign in to comment.