Marking text with unicodes
See original GitHub issueI’m using markjs in my project. This is basically used to highlight text. It works fine except for some text with unicode characters in it. For example text with characters “\xA0”
Here is the jsfiddle link for testing https://jsfiddle.net/trupti11/4zh3w0a8/2/
Here is the code sample
$(function() {
alert($('.txtHolder').text())
//this shows the extra characters in the text '\xA0'
alert($('.txtHolder').text().toSource());
//this does not work
$('.txtHolder1').mark($('.txtHolder1').text());
//this works
$('.txtHolder2').mark($('.txtHolder2').text());
});
Environment
- Browser FireFox 51
- mark.js
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Marking text with unicode characters - Stack Overflow
This is basically used to highlight text. It works fine except for some text with unicode characters in it. For example text with...
Read more >H34: Using a Unicode right-to-left mark (RLM) or left-to ... - W3C
Unicode right-to-left marks and left-to-right marks can be entered directly or by means of character entities or numeric character references, as shown here....
Read more >“✓” U+2713 Check Mark Unicode Character - Compart
Unicode Character “✓” (U+2713). ✓. Name: Check Mark. Unicode Version: 1.1 (June 1993). Block: Dingbats, U+2700 - U+27BF. Plane: Basic Multilingual Plane, ...
Read more >How to use decoration markers to highlight text - Bing Search ...
Bing uses either Unicode characters or HTML tags to mark the words or phrases in the webpage's name, display URL, and snippet text....
Read more >Specials (Unicode block) - Wikipedia
Specials is a short Unicode block of characters allocated at the very end of the Basic ... MARK character can be inserted at...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @pravid!
What are you trying to accomplish?
The
txtHolder1
class doesn’t exist. And\xA0
is unicode for a non-breaking whitespace. This is ignored when you set theseparateWordSearch
option totrue
(default setting) because each key word is targeted separately.@pravid You’ve now shown us your third JSFiddle, still with invalid HTML and invalid mark.js options. “lect” and “sen” are no valid HTML elements! I don’t like to debug your application to get something that can be used for tests.
Anyway, it didn’t work because you’re calling
.mark()
two times, with different strings, but with space at the end and the beginning in each of them. So, what happens is that if you mark the first sentence (that has multiple spaces at the end), it also wraps all blanks until.txtHolder2
. And if you then try to mark the second keyword which also requires blanks at the beginning, then there are no blanks that can be wrapped, thus there is no match for the second keyword. If you pass blanks to mark.js they will be merged, but it’s still necessary to have at least one blank otherwise no match is found (introduced in #97). To solve this, just trim the keyword before you pass it along to mark.js, usingstring.trim()
.This is you working fiddle.
In future, please provide one simple fiddle with valid HTML and a clear question. Thank you!