Highlight line in react-syntax-highlighter
You can hack on the generated span
s. Firstly, without talking about React, let us use plain jQuery to solve the problem:
Open the demo, then run
$(".language-javascript>span:nth-child(3)").css('background-color', 'blue')
and you will see the 3
rd line being blue!
Secondly, let us make it work in React. You can use some libraries to inject css codes like .language-javascript>span:nth-child(3) {background-color: blue;}
(where 3
is the line number you want to highlight) into React component tree.
Automatic line break in js SyntaxHighlighter
I don't actually use SyntaxHighlight, but it seems to be possible to attach an white-space: pre-wrap
CSS style to the <pre>
or <script>
tag that SyntaxHighlight uses.
HTML (using <pre>
):
<pre class="brush: js" class="syntaxhighlight">
/**
* SyntaxHighlighter
*/
function foo()
{
if (counter <= 10)
return;
// it works!
}
</pre>
HTML (using <script>
):
<script type="syntaxhighlighter" class="syntaxhighlight brush: js"><![CDATA[
/**
* SyntaxHighlighter
*/
function foo()
{
if (counter <= 10)
return;
// it works!
}
]]></script>
CSS:
.syntaxhighlight {
white-space: pre-wrap;
}
How can I insert a line break into a Text component in React Native?
This should do it:
<Text>
Hi~{"\n"}
this is a test message.
</Text>
Related Topics
How to Grab the CSS Truncated Text via Jquery
Detecting Width: Auto in Jquery
How to Get New Image Size Dimension After Giving Object-Fit:Contain Property to the Image Tag
Cannot Return CSS Property of HTML Element
How to Disable Caching of Static Assets Like .CSS and .Js in Jsf2
Browser Support for Angular Material
How to Over-Ride CSS with User-CSS on Mobile Safari
How to Make Content Load When the User Scrolls Down to It
Get CSS Not-Computed Property-Value with JavaScript Only
Disable Double Tap Zoom/Resize on Safari iOS12***
Transitioning Affixed Navigation Bar - CSS
Click Table Row and Get Value of All Cells
Bootstrap 4 Input Field in Popover
How to Check If CSS Calc() Is Available Using JavaScript
Android Webview, Loading JavaScript File in Assets Folder