But for now, we need to focus on unit testing. I actually just did some minor testing today, and I've already found a few issues! One of the main ones was with our stripHTMLTags method. It's very, very specific, but who knows, it might pop up in a few of the books' descriptions, causing some issues.
Basically, the name of stripHTMLTags is what we use it for. LibriVox's API and RSS feeds provide descriptions of each book. In our search results, I have previously coded it such that short bits of the description are displayed below each book. This is fine, until you notice that all descriptions have HTML tags in them - bold, italics, links, etc. and this ruins JQueryMobile's list. As such, we need a way to remove the HTML tags so that the list displays nicely, and for the most part, this method performs that well. However, under very specific circumstances, the method will result in large blocks of text being accidentally excluded from the description.
Imagine you had text like this for your description:
"<b>The left angle bracket, also known as <, is often used as a less than sign. On the other hand, the right angle bracket, known as >, is often used as a greater than sign.</b>"
You'd expect something like:
"The left angle bracket, also known as <, is often used as a less than sign. On the other hand, the right angle bracket, known as >, is often used as a greater than sign."
to be your output. However, our method is outputting:
"The left angle bracket, also known as , is often used as a greater than sign."
And this can easily be seen why, we're using this code for our stripHTMLTags method:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stripHTMLTags(str) { | |
return str.replace(/<(?:.|\n)*?>/gm, ''); | |
} |
Anyways, that's it for today; I hope to find more bugs tomorrow!
I just grabbed librifox.net, so we're covered ;-)
ReplyDeleteGreat post! The example you provide is clear and easy to follow, and illustrates your point well. Dealing with markup, HTML and other, will be something you will encounter frequently, so it is no surprise that we have to deal with it here.
hello
ReplyDeleteCan’t forget about the extra security that a static site provides. I also am stoked about INK for All's ability to export articles as a Markdown format. Historically, I had went with wp, just made the decision that a static site is the best option for my company’s blog. Always thought that WordPress was a little much: http://bit.ly/2ECXoDa