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

selection.text() contains extra whitespace #304

Closed
domehead100 opened this issue Apr 28, 2015 · 2 comments
Closed

selection.text() contains extra whitespace #304

domehead100 opened this issue Apr 28, 2015 · 2 comments

Comments

@domehead100
Copy link

I'm dealing with HTML that is generated via an RTF -> HTML conversion. That conversion makes use of spans for formatting text runs from the RTF (which generates a lot of spans!).

The HTML down below represents the text "female presents to the ED with a Chief Complaint of Shoulder Pain".

When I select this text in the browser (Chrome), and do rangy.getSelection().text(), I end up with an extra space in the text where new spans start. So, I end up with two spaces between the words "female" and "presents" and two spaces between "Complaint of" and "Shoulder".

From some experimentation, I can use some regexes to get the HTML from the selection and remove all of the tags and whitespace between tags, and this gets me the correct text: rangy.getSelection().toHtml().replace(/>\s+</gm, "><").replace(/<[^>]*>/gm, "");

but I was wondering if there's something I'm missing here or if this is a known behavior of rangy?

<span style="font-family:Arial; font-size:11pt; font-weight:normal; text-decoration:none" data-point-size="11">female</span>
        <span style="font-family:Arial; font-size:11pt; font-weight:normal; text-decoration:none" data-point-size="11"> presents to the ED with a Chief Complaint of </span>
        <span style="font-family:Arial; font-size:11pt; font-weight:normal; text-decoration:none" data-point-size="11">Shoulder Pain</span>
@timdown
Copy link
Owner

timdown commented May 3, 2015

Definitely a bug. I'm working on it now.

@timdown
Copy link
Owner

timdown commented May 3, 2015

Fixed. Will be in next release.

@timdown timdown closed this as completed May 3, 2015
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