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.
4 ответов
+ 1
You need this I think: <html>
0
For more info :
https://devpractical.com/display-html-tags-as-plain-text/
0
Yes it worked. Thank you.
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 '&' then '<' by '<', 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>•</body>');
// output:
// <body>&bull;</body>