react-magic icon indicating copy to clipboard operation
react-magic copied to clipboard

How to handle escape character in attribute?

Open xcv58 opened this issue 9 years ago • 1 comments

I have html string like this:

var html = '<div class="content" data-content="Some text. &lt;a href=&quot;https://google.com/&quot; target=&quot;_blank&quot; class=&quot;external&quot;&gt;Google!&lt;/a&gt;">internal text</div>'

It has data-content attribute which contains &lt;, &gt; and &quot;.

The output is:

<div className="content" data-content="Some text. <a href=&quot;https://google.com/" target="_blank" class="external">Google!</a>">internal text</div>

But it's not a valid jsx code.

I uses this fork to handle such case: https://github.com/xcv58/react-magic/commit/ed1234330f26c834fa642fd468373753ff44ad6f

But I'm not sure whether it's correct way.

xcv58 avatar Feb 20 '16 22:02 xcv58

I am having a similar problem with { and } characters.

kasbah avatar Aug 12 '16 22:08 kasbah