Show formatted HTML line as popup? - html

I am having a one single row with text with HTML-tags. Example.
html_string = '<!DOCTYPE html><html><body> <h1> My First Heading</h1> <p> My first paragraph.</p> </body> </html> '.
I want to give the value of html_string back as a formatted HTML text like that:
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
Best would be in a popup. Anyone got any idea? Best would be a function module or so. I've been looking around for some while but I have not found anything which fits my requirements.

I just found exactly what I needed. This might help any future programmers:
https://help.sap.com/doc/abapdocu_750_index_htm/7.50/de-DE/abenstring_function_escape_abexa.htm
REPORT demo_escape_html.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA: body TYPE string,
esc_body TYPE string.
body = `<table border> `
&& `<tr><td>11</td><td>12</td></tr> `
&& `<tr><td>21</td><td>22</td></tr> `
&& `</table>`.
esc_body = escape( val = body
format = cl_abap_format=>e_html_text ).
cl_demo_output=>new(
)->begin_section( 'Original text'
)->write_text( body
)->next_section( 'Original text formatted as HTML'
)->write_html( body
)->next_section( 'Escaped text'
)->write_text( esc_body
)->next_section( 'Escaped text formatted as HTML'
)->write_html( esc_body
)->display( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).

If the HTML is XHTML (XML-compatible), then you may display it like any other XML, and the integrated Windows browser will automatically indent the XML levels:
DATA l_xml TYPE string.
cl_abap_browser=>show_xml( xml_string = l_xml title = 'text' ).
If the HTML is not XHTML, there's no SAP program which interprets "begin-end" tags (like <br>, <li>, etc.)

Related

JSoup Add Wrapper div after body

I am trying to add a <div class="wrapper"> to my generated html after the body tag. I want the ending </div> to be before the ending </body>. So far I have
private String addWrapper(String html) {
Document doc = Jsoup.parse(html);
Element e = doc.select("body").first().appendElement("div");
e.attr("class", "wrapper");
return doc.toString();
}
and I am getting
</head>
<body>
</head>
<p>Heyo</p>
<div class="wrapper"></div>
</body>
</html>
I also can't figure out why I am getting "</head>" in the html too. I only get it when I use JSoup.
Jsoup Document normalizes the text with normalise method. The method is here in Document class. So It wraps with and tags.
In Jsoup.parse() method it can take three parameter, parse(String html, String baseUri, Parser parser);
We will give the parser parameter as Parser.xmlParser which is using XMLTreeBuilder (Otherwise it uses HtmlTreeBuilder and it normalises html.).
I tried, latest code (it may be optimize) :
String html = "<body></head><p>Heyo</p></body>";
Document doc = Jsoup.parse(html, "", Parser.xmlParser());
Attributes attributes = new Attributes();
attributes.put("class","wrapper");
Element e = new Element(Tag.valueOf("div"), "", attributes);
e.html(doc.select("body").html());
doc.select("body").html(e.toString());
System.out.println(doc.toString());

Line breaks are not rendered in MVC Razor View

I have the following string value generated in the controller.
cc.lstchat = "Reply the Number with your question... <br />";
foreach (clsChat item in lstchat)
{
cc.lstchat =cc.lstchat + item.DisplayNumber+". " + item.ChatItem+" <br/> ";
}
Now i'm trying to display above string value inside a div tag in my view but it does not render the line breaks.
<div id="divChat" style="width:400px;height:300px;border:double">
#Model.lstchat.ToString()
</div>
Try the #Html.Raw method
#Html.Raw(Model.lstchat)
Use Html.Raw() it is used to render any string as HTML.
`#Html.Raw("input data in here is rendered as HTML only")`
please please be careful with #Html.Raw() because of HTML injection (eg my comment will be <script>...</script> test - that an XSS right away. If you just want line breaks - consider this answer:
#Html.Raw(Html.Encode(Model.CommentText).Replace("\n", "<br />"))

HTML is shown as plain text in dojo widget

I have a dojo widget with generated content, text message in my case.
Message text is a formatted text with <b>, <i> etc. tags. When I put it to my widget via ${messageText} it is shown as it is a plain text.
How to make my widget parse all these tags to DOM nodes?
upd
.jsp fragment:
<script>
(new MyWidget({
text: "<b>message</b>"
}).placeAt(dojo.byId("placeWidgetHere");
</script>
<div id="placeWidgetHere"></div>
widget .html template:
<div>${text}</div>
Instead of using substitution variables (which is not recommended), you can use an attribute map on your custom widget.
<div>
<span data-dojo-attach-point="messageTextNode"></span>
</div>
declare('MyWidget'], [TemplatedMixin], {
template: ...,
messageText: '',
_setMessageTextAttr: { node: "messageTextNode", type: "innerHTML" },
});
new MyWidget({
messageText: "<b>message</b>"
}, "placeWidgetHere");
The problem is that messageText has "<" and ">" symbols converted to "<" and ">" respectively.
I added .replace(/</g, "<").replace(/>/g, ">") to messageText and that began to work properly.
Thanks to everyone who tried to help me.

color of apache wicket component

I have the following code:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd"
xml:lang="en" lang="en">
<body>
<wicket:panel>
<div wicket:id="serviceListContainer">
<table>
<tr wicket:id="serviceListView">
<td>
<span wicket:id="service.name"></span>
</td>
<td>
<span wicket:id="service.state"></span> <!-- I WANT TO COLOR THIS PART IN RED! -->
</td>
</tr>
</table>
</div>
</wicket:panel>
</body>
</html>
How can I change the color of the output text that will replace "service.state"? I tried with <font color="red"> but it didn't make any difference.
Thanks!
Other answers have indicated how you can add the style="..." attribute in the HTML template. If, on the other hand, that you do not wish to do this statically (say, you need to calculate the color and then add it to the component), you should add an AttributeModifier to the Component1.
Example (untested):
Label l = new Label("service.state", ...);
IModel<String> colorModel = new AbstractReadOnlyModel<String>() {
public String getObject() {
return "color: red;"; // Dummy example
}
}; // Some model, holding a string representation of a CSS style attribute (e.g., "color: ...;") based on some date and/or calculation
l.add(new AttributeModifier("style", true, colorModel);
You could even use a SimpleAttributeModifier if you don't need the pull-based model:
Label l = new Label("service.state", ...);
String styleAttr = "color: red;";
l.add(new SimpleAttributeModifier("style", styleAttr));
1) Provided that setRenderBodyOnly(true) has not been called. That would remove the wrapping <span> element from the output.
From W3Schools:
The <font> tag is deprecated in HTML 4, and removed from HTML5.
The World Wide Web Consortium (W3C) has removed the tag from
its recommendations. In HTML 4, style sheets (CSS) should be used
to define the layout and display properties for many HTML elements.
Use styles, even if it is inline styling, instead:
<span style="color:red">this is red text</span>
If you're using Wicket you'll want to make sure you're not using setRenderBodyOnly(true) on the Component with id service.state, as this would strip the <span> tag with the style.
<span wicket:id="service.state" style="color:red"></span>
or better is to use proper css classes

How do I set an HTML class attribute in Markdown?

If I have some Markdown like
## My Title
A paragraph of content here.
code_line(1);
// a code comment
class MoreCode { }
and more text to follow...
How can I set a class on the <code> block that's generated in the middle there? I want to have it output
<code class=’prettyprint’>
code_line(1);
// a code comment
class More Code { }
</code>
But I can't seem to set it. I do not have control over the Markdown code being run, only over the content.
You can embed HTML in Markdown. Type literally what you want, with no indent.
<code class="prettyprint">
code_line(1);
// a code comment
class More Code { }
</code>
For the specific case of syntax highlighting following the back ticks at the start of a fenced code block with the language works just about everywhere these days.
```js
code_line(1);
// a code comment
class MoreCode { }
```
Though not answering the question exactly. You can use a different render too like Maruku or Kramdown:
## My Title
A paragraph of content here.
~~~
code_line(1);
// a code comment
class MoreCode { }
~~~
{: .prettyprint}
and more text to follow...
Output (tested with haml & kramdown):
<pre class="prettyprint"><code>
code_line(1);
// a code comment
class MoreCode { }
</code></pre>
Kramdown syntax: http://kramdown.rubyforge.org/quickref.html#block-attributes
Markdown has an extension (attr_list.py) which allows you to use Maruku's {: .classname} syntax.
Markdown Extra supports class and id attributes using curly braces. See: https://michelf.ca/projects/php-markdown/extra/#spe-attr