I was trying to display below code in REACT webpage but it not showing as code. its displaying as actual elements. how to display below button codes as code ?
<code>
<pre>
<Button className='btn-grv' variant="primary" >Primary</Button>
<Button className='btn-grv' variant="blue">Link</Button>
<Button className='btn-grv' variant="dark">Dark</Button>
<Button className='btn-grv' variant="secondary">Secondary</Button>
<Button className='btn-grv' variant="success">Success</Button>
<Button className='btn-grv' variant="warning">Warning</Button>
<Button className='btn-grv' variant="danger">Danger</Button>
<Button className='btn-grv' variant="info">Info</Button>
<Button className='btn-grv' variant="light">Light</Button>
</pre>
</code>
CodePudding user response:
You can use html special characters.
Replace the <
and >
with <
and >
.
https://dev.w3.org/html5/html-author/charref
CodePudding user response:
This Page will transform you Code to "special characters":
https://de.functions-online.com/htmlspecialchars.html
Result should be:
<code>
<pre>
<Button className='btn-grv' variant="primary" >Primary</Button>
<Button className='btn-grv' variant="blue">Link</Button>
<Button className='btn-grv' variant="dark">Dark</Button>
<Button className='btn-grv' variant="secondary">Secondary</Button>
<Button className='btn-grv' variant="success">Success</Button>
<Button className='btn-grv' variant="warning">Warning</Button>
<Button className='btn-grv' variant="danger">Danger</Button>
<Button className='btn-grv' variant="info">Info</Button>
<Button className='btn-grv' variant="light">Light</Button>
</pre>
</code>
CodePudding user response:
<code>
<pre>
<Button className='btn-grv' variant="primary" >Primary</Button>
<Button className='btn-grv' variant="blue">Link</Button>
<Button className='btn-grv' variant="dark">Dark</Button>
<Button className='btn-grv' variant="secondary">Secondary</Button>
<Button className='btn-grv' variant="success">Success</Button>
<Button className='btn-grv' variant="warning">Warning</Button>
<Button className='btn-grv' variant="danger">Danger</Button>
<Button className='btn-grv' variant="info">Info</Button>
<Button className='btn-grv' variant="light">Light</Button>
</pre>
</code>
CodePudding user response:
or you can past it to pre as an inner text
const i = document.querySelector('pre');
i.innerText = `
<Button className='btn-grv' variant="primary" >Primary</Button>
<Button className='btn-grv' variant="blue">Link</Button>
<Button className='btn-grv' variant="dark">Dark</Button>
<Button className='btn-grv' variant="secondary">Secondary</Button>
<Button className='btn-grv' variant="success">Success</Button>
<Button className='btn-grv' variant="warning">Warning</Button>
<Button className='btn-grv' variant="danger">Danger</Button>
<Button className='btn-grv' variant="info">Info</Button>
<Button className='btn-grv' variant="light">Light</Button>
`;
<code>
<pre>
</pre>
</code>