Score:0

Why is
changed to
?

mn flag

After I edit a block in Full HTML form CKEditor on Source mode and save, Drupal changes <br> to <br />.

Drupal also seems to me to unify some HTML tags into one line.

This

<p>
<!-- -->
<br>

Becomes something like this

<p><!-- --><br />

In /admin/config/content/formats/manage/full_html the only filters that are on are:

  • Align images
  • Caption images
  • Track images uploaded via a text editor

The Correct faulty and chopped off HTML filter isn't on.

It might be that the very work on Full HTML mode causes this because it's "full" without any sugar syntax. If so, manually changing the HTML level of nearly 30 blocks and also hundreds of nodes to Restriced HTML is not something I want to do.

Why is this happening? How do I prevent it?

id flag
"Full HTML" is just a label of a text format, which is installed in Drupal by default. A text format is essentially the sum of its filters. CKEditor also does things. I can't determine from the Question if this is actually about CKEditor.
Jaypan avatar
de flag
They both do the same thing, and `<br />` is compatible with more doctypes, which is why the editor would default to this. What is your reasoning behind wanting to use `<br>` tags instead?
id flag
Is this question simply https://www.drupal.org/project/drupal/issues/3351660 ?
somo avatar
mn flag
@Jaypan using `<br>` instead `<br />` is just easier for me to read in condensed HTML text., the same goes for multi-line instead single-line.
Score:1
us flag

<br> is changed to <br /> because all the HTML markup used as block or node content is passed to Html::normalize(), which calls Html::serialize() which uses DOMDocument::saveXML(). The latter is what changes <br> to <br />. (It would also do the same for any tag without content.)

public static function serialize(\DOMDocument $document) {
  $body_node = $document->getElementsByTagName('body')->item(0);
  $html = '';
  if ($body_node !== NULL) {
    foreach ($body_node->getElementsByTagName('script') as $node) {
      static::escapeCdataElement($node);
    }
    foreach ($body_node->getElementsByTagName('style') as $node) {
      static::escapeCdataElement($node, '/*', '*/');
    }
    foreach ($body_node->childNodes as $node) {
      $html .= $document->saveXML($node);
    }
  }
  return $html;
}

That is not possible to change.

As for why the text is shown on a single line, that is what CKEditor 5 actually does. The issue linked by @cilefen in his comment (CKEditor 5 saves content as single line HTML making revision diffing impossible) contains a link to a feature request opened in the CKEditor 5 issue queue (Output formatted HTML code).
That needs to be implemented in CKEditor 5; then Drupal needs to use the release it implements that.

somo avatar
mn flag
apaderno, thank you. I think that the best workaround for both problems is just working on the HTML in a native app text editor (such as Geany or VSCode), change it from there and then re-paste it edited into the block source code.
apaderno avatar
us flag
It will not work to avoid `<br>` is changed to `<br />`, though, as `Html::normalize()` is always called by Drupal when a node/block is saved.
somo avatar
mn flag
Yes, I meant, it will be easy to edit outside and paste into Drupal but if the HTML is small (say, about 50 lines) than it's okay from Drupal. Thanks again for your help.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.