Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start tag of empty head element is not omitted #43

Closed
4 tasks done
0f-0b opened this issue Sep 14, 2024 · 6 comments
Closed
4 tasks done

Start tag of empty head element is not omitted #43

0f-0b opened this issue Sep 14, 2024 · 6 comments
Labels
💪 phase/solved Post is done

Comments

@0f-0b
Copy link

0f-0b commented Sep 14, 2024

Initial checklist

Affected packages and versions

hast-util-to-html@9.0.2

Link to runnable example

No response

Steps to reproduce

Run the code below.

import { toHtml } from "hast-util-to-html";

console.log(toHtml(
  {
    type: "root",
    children: [
      {
        type: "element",
        tagName: "html",
        children: [
          {
            type: "element",
            tagName: "head",
            children: [],
          },
          {
            type: "element",
            tagName: "body",
            children: [],
          },
        ],
      },
    ],
  },
  { omitOptionalTags: true },
));

Expected behavior

Empty output. The start tag of the head element is omitted because the element is empty.

Actual behavior

The output is <head>.

Affected runtime and version

node@22.8.0

Affected package manager and version

npm@10.8.3

Affected OS and version

No response

Build and bundle tools

No response

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Sep 14, 2024
@wooorm
Copy link
Member

wooorm commented Sep 14, 2024

Can you please clarify actual/expected with code? Thanks

@0f-0b
Copy link
Author

0f-0b commented Sep 14, 2024

Can you please clarify actual/expected with code?

The actual output is a redundant start tag:

<head>

The expected output is an empty string:


@wooorm
Copy link
Member

wooorm commented Sep 16, 2024

Did you see the end of the section you linked to?

This section assumes that the document is conforming, in particular, that there are no content model violations. Omitting tags in the fashion described in this section in a document that does not conform to the content models described in this specification is likely to result in unexpected DOM differences (this is, in part, what the content models are designed to avoid).

Your empty document is not conforming: you need to have a title.

@0f-0b
Copy link
Author

0f-0b commented Sep 16, 2024

Your empty document is not conforming: you need to have a title.

It is, when used as an iframe srcdoc document.

@wooorm
Copy link
Member

wooorm commented Sep 16, 2024

and is that what you’re doing? that seems unlikely 😅

@wooorm wooorm closed this as completed in 1c938b9 Sep 16, 2024
@wooorm wooorm added the 💪 phase/solved Post is done label Sep 16, 2024
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Sep 16, 2024
@wooorm
Copy link
Member

wooorm commented Sep 16, 2024

released in 9.0.3!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done
Development

No branches or pull requests

2 participants