0

How can I render a component inside a HTML <code> element just as a text?

<code>
  <DesktopHeader>
    <a href="/projects">Projects</a>
  </DesktopHeader>
</code>

In my situation it renders my component again but I want to use it inside a documentation to just show how to pass props to a component.

5
  • you can put it inside backticks and make it a string. Commented Jun 21, 2020 at 18:47
  • This does unfortunately not work. Commented Jun 21, 2020 at 18:50
  • What do you mean by inside a documentation? Commented Jun 21, 2020 at 18:51
  • I am rendering a component and underneath I want to show the code for the component. Like it's done with Storybook JS. Commented Jun 21, 2020 at 18:52
  • You could use images like this instead though I don't know if thats what you're looking for carbon.now.sh Commented Jun 21, 2020 at 18:53

1 Answer 1

4

This is not a perfect matchup for what you intend to do but you can escape your markups with &lt; for <, &gt; for >, &quot; for " (quotes), and also &nbsp; for (spaces).

So it will become something like this:

<code>
&lt;DesktopHeader&gt;<br/>
&nbsp;&nbsp;&lt;a href=&quot;/projects&quot;&gt;Projects&lt;/a&gt;<br/> &lt;/DesktopHeader&gt;
</code>

NOTE: Generally every character with an UTF-8 code above 127 is not interchangeable between the "normal" Western ISO-8859-1 encoding and UTF-8. But to creating HTML markups knowing these three (&lt;, &gt;, &nbsp;, and &quot;) would be enough. I'm also found a link that can be useful for generating markups automatically.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.