I have a scenario where-in I fetch some text from the database which is formatted using HTML as below:
public static void main(String args[ ]) { <br> int x =10;}
I'm using syntax highlighter to do some highlighting. The String above will be fetched from the database, and rendered in the html page using the pre tag as shown below:
<p><pre class="brush: java;">#exam.description</pre></p>
Where exam.description will contain the HTML formatted source code that is shown above. The resultant HTML rendered is as shown below in the screenshot!
How to ensue that the HTML tags inside the source code are respected as HTML tags? I checked the configuration options for the Syntax Highlighter and there seems to be none that I could use to escape the HTML! Any suggestions?
Your question doesn't make much sense, maybe you should rephrase it, in any case:
<p><pre class="brush: java;">Line 1\nLine 2\nLine 3\n</pre></p>
Will return the data in multiple lines, and
<p><pre class="brush: java;">Line 1<br>\nLine 2\nLine 3\n</pre></p>
Will also return multiple lines and add an extra line between Line 1 and Line 2.
So in any case, your code should work UNLESS you are escaping the data returned from the function (java function), and the < and > (or just one of them) are escaped
Related
I have string like as follow, which is generated in mvc controller and display in a view within a table cell. S020050A,S020050B,S020050C,S020050D,S020050E,S020050F
,S020050G,S020050H,S020050I,S020050J,S020050K,S020050L
As I want to wrap the text on every 5 words, I have pushed
tag on every 5 words, so that string look like as follow
S020050A,S020050B,S020050C,S020050D,S020050E,S020050F
,S020050G,S020050H,S020050I,S020050J,S020050K,S020050L
I am intended to break the line from there, but in a view it just shows as it is, tag not interpreted as new line but simply as a part of string
I tried putting Environment.Newline and /n as well, when I did this in simple html page, it worked, so I believe it asp.net own mechanism which suppress tag, how I can make tag interpreted as new line?
I could solve it, from controller code (back end) add -> \n instead where you want line break and then in view use this style ->
style="white-space: pre-line"
In a string like
Hallo, this is <code>`code`</code> and this `is code again`.
To analyse it, parse it with regex?
In this example the user just typed the far right ` at the very last. The first "code" has obviously already been surrounded by HTML.
I need a regex to get the next code indicated part.
There always be one series, that is valid markdown AND not already surrounded by the corresponding HTML tags.
How to get this specific series (regardless if it's *, **, ___, ` or whatever)?
So what you want is a regex that only matches the markdown that isn't surrounded by HTML tags right ?
You can use something like this :
/(?:[^<>]|^)(`[^<>].*?`)/
This will only match the text placed inside `` that aren't directly placed next to a < or > character. This way, no matter what the HTML tag is inside the <...>, the `code` won't match.
See this Regex101.com
If you want to match every emphasized string that is not tagged with "code" you can use
(?<!<code>)`[\w ]+`
You can test it on regex101.com
I create HTML documents from a rst-formated text, with the help of Sphinx. I need to display some Japanese words with furiganas (=small characters above the words), something like that :
I'd like to produce HTML displaying furiganas thanks to the < ruby > tag.
I can't figure out how to get this result. I tried to:
insert raw HTML code with the .. raw:: html directive but it breaks my line into several paragraphs.
use the :superscript: directive but the text in furigana is written beside the text, not above.
use the :role: directive to create a link between the text and a CSS class of my own. But the :role: directive can only be applied to a segment of text, not to TWO segments as required by the furiganas (=text + text above it).
Any idea to help me ?
As long as I know, there's no simple way to get the expected result.
For a specific project, I choosed not to generate the furiganas with the help of Sphinx but to modify the .html files afterwards. See the add_ons/add_furiganas.py script and the result here. Yes, it's a quick-and-dirty trick :(
I would expect that the following:
<div style="padding-top:90px;"><%= u.one_line %></div>
simply pulls whatever is in u.one_line (which in my case is text from database), and puts it in the html file. The problem I'm having is that sometimes, u.one_line has text with formatted html in it (just line breaks). For example sometimes:
u.one_line is "This is < / b r > awesome"
and I would like the page to process the fact that there's a line break in there... I had to put it with spaces up ^^^ here because the browser would not display it otherwise on stackoverflow. But on my server it's typed correctly, unfortunately instead of the browser processing the line break, it prints out the "< / b r>" part...
I hope you guys understand what I mean :(?
always remember to use raw or html_safe for html output in rails because rails by default auto-escapes html content for protecting against XSS attacks.
for more see
When to use raw() and when to use .html_safe
HTML myHtml=new HTML(SafeHtmlUtils.fromString("<i>Test</i>"));
HTML myHtml2=new HTML("<i>Test2</i>");
testHTMLPanel.add(myHtml);
testHTMLPanel.add(myHtml2);
OUTPUT:
<i>Test</i>
Test2
The right output should be the formmatted text like the second one. Other Gwt html widget also have the similar problem.
I am using Eclipse Juno.
SafeHtmlUtils.fromString(String s)
HTML-escapes its argument and returns the result wrapped as a SafeHtml.
That means that you get somthing like .0;i&#.62;Test&#.60;&#.47;i&.#62;
Check
https://developers.google.com/web-toolkit/doc/latest/DevGuideSecuritySafeHtml
It's a security thing:
The reason why you have SafeHtmlUtils.fromString(userString) is that you can take a dynamic string, for example from a user input, and create a html text from it. It's more safe than just use Html.setText(userString) because with setText(userString) it would be feasible to inject vulnerable code.
more about input validation: http://www.testingsecurity.com/input-validation