Appending HTML to document object adds additional unwanted tags.

조회 수: 4 (최근 30일)
Aidan Keay
Aidan Keay 2019년 6월 5일
댓글: Aidan Keay 2019년 6월 21일
Constructing a basic document, appending custom HTML and viewing the final document HTML.
import mlreportgen.dom.*;
doc=Document('doc','html');
htmlObj = HTML('<div><a href="https://www.mathworks.com">Mathworks</a></div>');
append(doc, htmlObj);
close(doc);
rptview(doc.OutputPath)
After appending to the document body we get:
<body onload="outline()">
<div><div><p><a href="https://www.mathworks.com"><span>Mathworks</span></a></p></div></div> %Additional tags.
</body></html>
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?
Thanks.

채택된 답변

Rahul Singhal
Rahul Singhal 2019년 6월 20일
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.*;
doc=Document('doc','html');
rawTextObj = RawText('<div><a href="https://www.mathworks.com">Mathworks</a></div>');
append(doc, rawTextObj);
close(doc);
rptview(doc.OutputPath);
And the corresponding generated report will have:
<body onload="outline()">
<div><a href="https://www.mathworks.com">Mathworks</a></div>
</body>
Thanks,
Rahul

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Report Generator Creation에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by