Techiio-author
Started by James CharlesSep 4, 2021

Open
want to write script in react-markdown file but all charactors escaped

0 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWES SHARE

I have problem on my markdown site using Next and react-markdown. I want to add some script like a embed tag of Github gist, but all the characters escaped. Is there any solution to unescape characters inside script tag?

I add rehypePlugins={[rehypeRaw]} to the so the HTML enabled:

// pages/post/[id].tsx
...
<ReactMarkdown components={components} rehypePlugins={[rehypeRaw]}>
{markdownBody}
</ReactMarkdown>
...

I tried:

// posts/somemarkdwon.md

## H1 title here

normal text here

<p>hi<br />hi</span></p>

<script>const hi = "3"; alert(hi);</script>

Output:

<h2>H1 title here</h2>
<p>normal text here</p>
<p>hi<br/>hi</p>
<script>const hi = &quot;3&quot;; alert(hi);</script>

"3" converted to &quot;3&quot; and the script got error.

Does anyone has good solution?

0 Replies

You must be Logged in to reply
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance