Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6879261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:49:26+00:00 2026-05-27T04:49:26+00:00

I have text that was created created with CKeditor , and it seems to

  • 0

I have text that was created created with CKeditor, and it seems to be inserting &nbsp; where spaces should be. And it appears to do similar conversions with >, <, &, etc. which is fine, except, when I make a DOMSelection, those codes are removed.

So, this is what is selected:

before<a href=\"http://wiki.teamliquid.net/starcraft2/Hatchery\" style=\"text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; \" title=\"Hatchery\">Hatchery</a> (2)

But this is what is actually in the DOM:

before<a href=\"http://wiki.teamliquid.net/starcraft2/Hatchery\" style=\"text-decoration: none; color: rgb(0, 43, 184); background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; \" title=\"Hatchery\">Hatchery</a>&nbsp;(2)

note that I outputted the selection and the original text stored in the database using variable.inspect, so all the quotes are escaped (they wouldn’t be when sent to the browser).


To save everyone the pain of looking for the difference:
From the first: Hatchery</a> (2) (The Selection)
From the second: Hatchery</a>&nbsp;(2) (The original)
These differences are at the very end of the selection.


So… there are three ways, I can see of, to approach this.

1) - Replace all characters commonly replaced with codes with their codes, 
     and hope for the best.
2) - Javascript may have some uncommon function / a library may exist that 
     replaces these characters for me (I think this might be the way CKeditor 
     does its character conversion).
3) - Figure out the way CKeditor converts and do the conversion exactly that way.

I’m using Ruby on Rails, but that shouldn’t matter for this problem.

Some other things that I found out that it converts:

1: It seems to only convert spaces to &nbsp; if the space(s) is before or after a tag:
   e.g.: "With quick&nbsp;<a href..."
2: It changes apostrophes to the hex value
   e.g.: "opponent&#39;s"
3: It changes "&" to "&amp;"
4: It changes angle brackets to "&gt;" and "&lt;" appropriately.

Does anyone have any thoughts on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:49:27+00:00Added an answer on May 27, 2026 at 4:49 am

    To encode html entities in str (your question title asks for this, if I understand correctly):

    $('<div/>').text(str).html();
    

    To decode html entities in str:

    $('<div/>').html(str).text();
    

    These rely on jQuery, but vanilla alternatives are basically the same but more verbose.

    To encode html entities in str:

    var el = document.createElement('div');
    el.innerText = str;
    el.innerHTML;
    

    To decode html entities in str:

    var el = document.createElement('div');
    el.innerHTML = str;
    el.innerText;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a non-form c# program that uses the NotifyIcon class. The text
For testing purposes I need to create sets of text files that have similar
I have text files that are Tab delimited. I created a Schema.ini like so:
I have created a text file to save the error in that created file.
There is a text file that I have created in my project root folder.
I have a report that will require chunks of text (that will be created
I have a Python script that reads through a text csv file and creates
I have text that looks like: My name is (Richard) and I cannot do
Currently I am doing this: I have text that looks like: Hello ${user.name}, this
I have Text file that contains data separated with a comma , . How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.