Open dsuurlant opened 1 year ago
I have a different environment than yours, but
I made it work with
$textWithTags = "<p>C<sup>8</sup>H<sup>10</sup>N<sub>4</sub>O<sub>2</sub></p>";
instead of
$textWithTags = "C<sup>8</sup>H<sup>10</sup>N<sub>4</sub>O<sub>2</sub>";
I suppose it is because in the readParagraph function, there is the following part
if (0 === $textRunContainers) {
$parent->addTextBreak(null, $paragraphStyle);
}
And then when writing it, in HTML writer for example, it does
if ($this->withoutP) {
$content = '<br />' . PHP_EOL;
} else {
$content = '<p> </p>' . PHP_EOL;
}
Note that adding a paragraph around your $textWithTags add also a text run
First, this seems to be a problem with all formatting tags (e.g. <b>
will cause similar results). Section expects a line break between its constituent elements; TextRun, however, does not. So, the following minor modification of your third ("whitespace") attempt seems to work:
$textRun = $section->addTextRun();
Html::addHtml($textRun, $textWithTags);
Likewise for a table cell:
$textRun = $cell->addTextRun();
Html::addHtml($textRun, $textWithTags);
Perhaps because for OOXML, " A section is a grouping of paragraphs that have a specific set of properties used to define the pages on which the text will appear."
Describe the Bug
When attempting to add text with
<sup>...</sup>
or<sub>...</sub>
tags usingHtml::addHtml
and placing it into a Section or Table Cell, the resulting text has unwanted line breaks. When placing it in aTextRun
, the text isn't rendered at all.Steps to Reproduce
Please provide a code sample that reproduces the issue.
Our target behavior is actually to render the text with
sub/sup
tags inside a table that is used with the template processor:In the above example, the text inside the table cell has line breaks as well.
Working example
We know this behaviour is possible as this does work in the
TemplateProcessor
with a TextRun:Now the sub/sup tags are rendered correctly on a single line.
Expected Behavior
I would expect the text to be rendered without line breaks whether in a table cell, a textrun, or any other element; with or without the TemplateProcessor.
Current Behavior
Text with
sub
orsup
HTML tags is rendered with line breaks.Context
Please fill in your environment information: