question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Marking text with unicodes

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Mottiecommented, Mar 10, 2017

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 the separateWordSearch option to true (default setting) because each key word is targeted separately.

0reactions
julmotcommented, Mar 14, 2017

@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, using string.trim().

This is you working fiddle.

In future, please provide one simple fiddle with valid HTML and a clear question. Thank you!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found