0

Html tag in paragraph

I am trying to explain <html> and <body> tag in my <p> tag, it is treating it as a tag. And not showing that tag as a part of paragraph discription. Can someone help please.

21st Mar 2021, 11:39 AM
R.M
R.M - avatar
4 ответов
+ 1
You need this I think: &lt;html&gt;
21st Mar 2021, 11:44 AM
dozule
dozule - avatar
21st Mar 2021, 11:52 AM
Jayakrishna 🇮🇳
0
Yes it worked. Thank you.
21st Mar 2021, 12:02 PM
R.M
R.M - avatar
0
to safely output html special char inside html (such as displaying tags), you must at least use 'html entities' to replace all '&' and '<' in the source code wich are not part of the html code itself (else it will be parsed as html code instead of html text content)... you can replace both at same time or start by replacing '&' by '&amp;' then '<' by '&lt;', to avoid replacing '&' inside html entities ;) // lambda function to replace both at once in a string: const escHtml = str => str.replace(/[&<]/g,ch => '&'+{'&':'amp','<':'lt'}[ch]+';'); // use: console.log(escHtml('<body>&bull;</body>'); // output: // &lt;body>&amp;bull;&lt;/body>
21st Mar 2021, 12:35 PM
visph
visph - avatar