Type in span/div respecting breakline and then transform to pre
Hello. I'm facing a situation here (studying purpose) where I type in a textarea and onkeyup it will copy the text to a span or div and after it, it will turn the component into a pre to use syntaxhighlighter.
I found out that I can change the breakline by replacing the text breakline (/\n/g,'
') i can change the modifier to break it, but if I add <br/> there, the syntaxhighlighter will show the <br/> and not jump to the next line.
I tried with text() and html(), and after render it in the page, I will call SyntaxHighlighter.highlight(); and the code will be transformed again.
here's what I done until now:
- <script type="text/javascript">
- // <![CDATA[
- function copiarIdentar() {
- $vn = '<pre class="brush: java">' + $('#codigo-escrito').val().replace(/\n/g, '
') + '</pre>';
- $('#codigo-identado').html($vn);
- SyntaxHighlighter.highlight();
- }
- // ]]>
- </script>
- <h:panelGroup layout="block" id="codigo-identado"></h:panelGroup>
- <h:form prependId="false">
- <p:inputTextarea value="#{compilador.codigo}" id="codigo-escrito" onkeyup="copiarIdentar()" />
- <p:commandButton value="Compilar" />
- </h:form>
It works, but it doesn't respect breakline, so, if I type 50 lines, it will show all in 1 line 