Skip to content

Script without body generates wrong html #474

Open

Description

@niklaswimmer

Hey, I tried to include script src="main.js; in my template's head which expands to <script src="main.js">. This is however wrong as script tags always need to be closed. The solution is to use script src="main.js" {} in the template instead. Maybe this can be improved by special casing the generation of script tags?

Activity

  1. tryoxiss commented on Apr 11, 2025

    @tryoxiss

    Not a maintainer, just trying to be helpful.

    Maud does this for all elements, if it is ended with a semicolon it will not place an end tag as it assumes self-closing. If it is ended with braces it will place an end tag. script src="main.js {} will work as expected.

    Though since HTML void elements are very limited -- you cant define custom void elements. It would make sense for maud to compile error (or at least raise a warning) when trying to use a void element as a block.

    Trying to use a block element as void (ended with ;) could either error or close the tag immeditely. Closing the tag immeditely wouldnt be very helpful as {} does the same thing (though it could make code look slightly more uniform in the head where eery element except script is void), so an error makes more sense. It would also allow the ; syntyax to perhaps be retired, though im not sure (as it does prevent adding children, and using smart {} would require that to be a compile error)

    Complete list of void elements:

    • <area>
    • <base>
    • <br>
    • <col>
    • <embed>
    • <hr>
    • <img>
    • <input>
    • <link>
    • <meta>
    • <param> (DEPRECATED)
    • <source>
    • <track>
    • <wbr>

    (Source: https://developer.mozilla.org/en-US/docs/Glossary/Void_element )

    In other words, if any of these are terminated with brackets {}, it would error. If any other element is terminated with a semicolon ;, it would error. If this were done, the ; synax could even be completely removed since it would then be able to figure out how to end the element based on what it is. (EDIT: Though it would need to disallow children in the brackets, so perhaps not)

    Sidenote: While we are on the topic of making it impossible to generate invalid HTML, perhaps it coul also be a good idea to require element names to be valid aswell. Because all custom elements need to have a hyphen (-). Maud could reject any elements without a hyphen that arent in a list of valid elements.

    Weather or not deprecated elements would be allowed or not im not sure, maybe it could emit a warning or bar behind a feature or something). It would be relatively simple to do this, since the rules for this are intentionally simple.

    Validating attributes would also be possible but much harder. Attributes have much more complex rules, theres a lot more of them, and more are added much more frequently. While it would be nice to validate attributes, I dont suspect it would be worth it for the added complexity.

    EDIT2: Related #478

  2. encounter commented on Apr 29, 2025

    @encounter

    How about if an element is void, ; retains the current behavior: img; -> <img>. If an element is not void, it emits a self-closing tag: script; -> <script/>.

    Alternatively, ; could always emit self-closing tags. This way there doesn't have to be extra logic to determine what tags are void or not. A few extra characters emitted for a solution that works with every tag.

    edit: I just learned that self-closing tags aren't valid in HTML5, how fun!

  3. encounter commented on Apr 29, 2025

    @encounter

    Related issue: #432

  4. tryoxiss commented on May 11, 2025

    @tryoxiss

    Likely somehow related to #181

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions