rangy icon indicating copy to clipboard operation
rangy copied to clipboard

Rangy to wrap selected text with single span

Open mustufasathaliya opened this issue 9 years ago • 6 comments

Hi is there any way to wrap selected text with single span , even if it contain html tag between . For eg my text is

<strong>Hello</strong> test rangy highlighter

Now when i highlight above text , than rangy add two span as below

<strong><span class="highlight">Hello</span></strong><span class="highlight"> test rangy highlighter</span>

But i want that selected text should wrap with single span as

<span class="highlight"><strong>Hello</strong>test rangy highlighter</span>

mustufasathaliya avatar Oct 29 '16 14:10 mustufasathaliya

Did you try using the surroundContents method? Or the Class Applier Module?

edsonharantes avatar Oct 29 '16 22:10 edsonharantes

I had used rangy Class Applier module, but it wrap only the text node. Can you please share me line of code to wrap entire selected content with single span

mustufasathaliya avatar Oct 30 '16 03:10 mustufasathaliya

I am also curious how this can be done. Say I have paragraphs with different styles and I want them to be applied to the group of text nodes, not separately to each one of them

romanovma avatar May 27 '19 09:05 romanovma

Does anyone have a solution? @romanovma @mustufasathaliya

ItsRyanWu avatar Jun 21 '19 09:06 ItsRyanWu

Did you find any solution @mustufasathaliya @edsonharantes @romanovma?

nishantmendiratta avatar Sep 01 '19 06:09 nishantmendiratta

The answer is using native Range API. @nishantmendiratta

ItsRyanWu avatar Dec 27 '19 14:12 ItsRyanWu