So I'm switching an internal style guide for a site we're working on from regular html to use reactjs. I've got example code and I'm using highlighting with prism.js. The highlighting seems to work fine, but line breaks don't. Even putting in br tags after every line has no effect. Anyone have any thoughts on this? Just some example code:
var Example = React.createClass({
render: function() {
return (
<div class="highlight">
<pre>
<code class="language-markup">
<label class="select">
<select class="selector">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</label>
</code>
</pre>
</div>
);
}
});
React.render(<Example />, document.getElementById('example'));
When it renders it looks like this.
<label class="select"><select class="selector"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select></label>
But I expect it to look like this:
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/0.0.1/prism.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/0.0.1/prism.min.css" rel="stylesheet"/>
<div class="highlight">
<pre>
<code class="language-markup">
<label class="select">
<select class="selector">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</label>
</code>
</pre>
</div>
Anyone know of a way to preserve the line breaks?
How to get Prism working with create-react-app — super quick. import React from "react"; import Prism from "prismjs"; Step 3: Select your preferred theme type from the prism website — ( I like Okadia) and hit that rather large DOWNLOAD CSS button at the foot of the page.
Syntax Highlighting with PrismJS Prism is a lightweight, extensible syntax highlighter that can be used when working with code blocks in markdown files in blog posts.
You need to pass a render prop to the Highlight component as in the example below. The above code block illustrates how you can highlight a simple code block with the prism-react-renderer package. The Highlight component passes several arguments to the render prop.
pdf [411KB], which is a compilation of past slides.) PRISM is a general programming language intended for symbolic-statistical modeling. It is a new and unprecedented programming language with learning ability for statistical parameters embedded in programs.
You can just code like this:
var Example = React.createClass({
render: function() {
return (
<div class="highlight">
<pre>
<code class="language-markup">
{`
<label class="select">
<select class="selector">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</label>
`}
</code>
</pre>
</div>
);
}
});
Demo is here.
The only shortage is the indent.
First: Use ReactDOMServer.renderToStaticMarkup
to render component to string
var inner = ReactDOMServer.renderToStaticMarkup(
<label className="select">
...
</label>
);
After Use JS Beautifier to prettify your string
inner = html_beautify(inner);
Finnaly Insert it to your code as string
<code className="language-markup">
{inner}
</code>
Url: http://jsfiddle.net/ohwz5ry2/2/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With