jgm/gitit — pull request #435 by wcaleb (2014-07-07 14:48:18+00:00)
Title: Handle search patterns that begin or end with punctuation

These changes to `search.js` do two things:

First, they escape regex metacharacters in `patt`. Previously, if the search pattern was something like `[Front Page]()`, then the script would treat `[Front Page]` as a regex character class and highlight all matches of `F`, `r`, `o`, etc.

Fixing that problem introduces another one, which is that searches beginning with punctuation would not match because of the hard-coded word boundary in the RegExp. Since `\b` matches between word characters and non-word-characters, but patterns like `[Front Page]()` typically appear after a non-word character in a file (like space), the regex would fail.

The ugly, but functional, work around is to change the regex start and end patterns if `patt` begins or ends with a non-word character, and then to preserve the non-word character that precedes the patt when replacing the regex with the highlight span.

P.S. Apologize for the extra commit messages, created by another commit that I reverted. Couldn't figure out how to do rebase, but if you need me to revise, and can advise me on how to make a cleaner pull request, I will.