Skip to content

Improper Handling of Missing Trailing Newline for Nested Void Tags #30

@bliutech

Description

@bliutech

An issue arises with this plugin when handling nested void tags without a trailing newline character. The following is a POC to demonstrate this bug.

Unformatted:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example Document</title>
</head>
<body>
    <a title="google.com" href="https://www.google.com"><img src="https://fastly.picsum.photos/id/675/200/300.jpg?hmac=c2gHO4_1hIFBRijtOhz09icBTxsdGCsMSYSs2XIDdAk" alt="dummy image"/></a>
</body>
</html>

Output of prettier-plugin-void-html:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example Document</title>
  </head>
  <body>
    <a title="google.com" href="https://www.google.com"
      ><img
        src="https://fastly.picsum.photos/id/675/200/300.jpg?hmac=c2gHO4_1hIFBRijtOhz09icBTxsdGCsMSYSs2XIDdAk"
        alt="dummy image"
      >
    /></a>
  </body>
</html>

Note specifically the addition of the /> as raw text following the properly closed void img tag. A current workaround is to simply add a newline after the img tag in the unformatted code and prettier-plugin-void-html handles it correctly. However, this seems like a common edge case that the plugin should try and handle.

Thanks for the creation of this project! It has proven to be quite useful. 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions