Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Words with vertical bar ('|') does not highlight #65

Open
ChenglimEar opened this issue Feb 25, 2016 · 1 comment
Open

Words with vertical bar ('|') does not highlight #65

ChenglimEar opened this issue Feb 25, 2016 · 1 comment

Comments

@ChenglimEar
Copy link

If you set the word to highlight to something like '|a', it doesn't work (that's a vertical bar and not a letter).

I've investigated this problem and found two places where it was problematic:

  1. I had to use the regular expression for the word such that "|a" became "[|]a". This works such that the initial part of the plugin code matches "|a" in the text area.

  2. The second part of the plugin code that actually searches for the match, "|a", to highlight fails because the "|" interferes with the regex being constructed in this line of code:

text = text.replace(new RegExp(match, 'g'), '<mark style="background-color:'+ color +';">$&</mark>', 'g');

Can you fix this? Inserting this line before the above line seems to fix it for me:

match = match.replace('|','[|]');

Thanks.

@garysieling
Copy link
Owner

The "words" parameter is a list of regexes, which is perhaps a bit unclear. You should be able to escape values you pass in as regexes. I could perhaps add an argument that takes non-regex words, although I'd have to research how to do this in a generalized way.

I did notice that there were rendering issues when a pipe or a > was in the middle of a word, which are now fixed. You can see the changes/new examples here:

ffd643b#diff-46eb058573e3998a7d10ba211eb90223

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants