Appending HTML to document object adds additional unwanted tags.

1 view (last 30 days)
Aidan Keay
Aidan Keay on 5 Jun 2019
Commented: Aidan Keay on 21 Jun 2019
Constructing a basic document, appending custom HTML and viewing the final document HTML.
import mlreportgen.dom.*;
htmlObj = HTML('<div><a href="">Mathworks</a></div>');
append(doc, htmlObj);
After appending to the document body we get:
<body onload="outline()">
<div><div><p><a href=""><span>Mathworks</span></a></p></div></div> %Additional tags.
I understand the HTML object has a wrapper element (the div in this case) which is wrapped around the html object. The main problem is the additional p and span tags. These unknown tags make document styling more difficult.
Is there any way to pass through HTML with the append function and no additional modification?

Accepted Answer

Rahul Singhal
Rahul Singhal on 20 Jun 2019
Hi Aidan,
If you want to add HTML content in a HTML report, and do not want additonal tags to be created, you can use the DOM mlreportgen.dom.RawText object.
So your script will look like:
import mlreportgen.dom.*;
rawTextObj = RawText('<div><a href="">Mathworks</a></div>');
append(doc, rawTextObj);
And the corresponding generated report will have:
<body onload="outline()">
<div><a href="">Mathworks</a></div>

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!