Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #7 from clarkbw/single-quote-titles

Single quote titles
  • Loading branch information...
commit ed615084ab9a36902922ed8b06ae1c438fac1bc6 2 parents bcf6b8a + 345732b
@kenshiro-o authored
Showing with 27 additions and 12 deletions.
  1. +14 −12 lib/converter/wikiToHTMLConverter.js
  2. +13 −0 test/wikiClientTest.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) {
View
13 test/wikiClientTest.js
@@ -59,6 +59,19 @@ vows.describe("Wikipedia search checks").addBatch({
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");
}
},
// end of html test
Please sign in to comment.
Something went wrong with that request. Please try again.