Escape a list element

This code block gets read by HTML as bulleted comments, though they are text. Is there a shorter method to prevent them from being formatted as list elements than escaping “<” and “>?”

<pre><code>
{state.messages.map(element =>
<ul messags={element.messages} />);}
let listItems = messsages.map(item =>
<li>{item}</li>
);

<ul>
{this.state.messages.map(element =>
<li>{element}</li>)}
</ul>
</code></pre>

image

Right, I don’t know if there is a better way, but you can obscure the HTML elements by using escapes for the < characters, with &lt;

<pre>
{state.messages.map(element =>
&lt;ul messags={element.messages} />);}
let listItems = messsages.map(item =>
&lt;li>{item}&lt;/li>
);

&lt;ul>
{this.state.messages.map(element =>
&lt;li>{element}&lt;/li>)}
&lt;/ul>
</pre>

It does seem like escaping them is the way to obscure the elements in HTML. There are escape character converters for blocks of text.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.