microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
160.38k stars 28.1k forks source link

Lower-case `d` starting `<!docType>` HTML tag causes it to render in the Markdown previewer. #216834

Closed RokeJulianLockhart closed 1 day ago

RokeJulianLockhart commented 1 week ago
Does this issue occur when all extensions are disabled? Yes
VS Code Version code-insiders-1.91.0-1718942998.el8.rpm
OS Version cpe:/o:fedoraproject:fedora:40

Steps to Reproduce

  1. <!doctype Markdown>

    Screenshot_20240621_182019

    I use camelCase for all HTML tags, so I noticed this when I entered <!docType Markdown>.

  2. <!Doctype Markdown>

    Screenshot_20240621_182023

    Solely the first letter matters, which doesn't make any sense - if it should always be capitalized, then the check should validate the entire tag content.

mjbvz commented 1 week ago

Please justify the use case and why this should be supported

RokeJulianLockhart commented 1 week ago

https://github.com/microsoft/vscode/issues/216834#issuecomment-2187144310

@mjbvz:

  1. Inline HTML should be as valid as is possible, meaning that <docType> should be used in a Markdown document containing HTML.
  2. HTML is case-insensitive, and readability matters, so camelCase HTML is common.
    1. The parsing is nonsensical (why would the case of the first letter determine anything?)
mjbvz commented 1 week ago

This doesn't answer my question: why do you need to write a docType tag at all? The resulting html isn't valid

RokeJulianLockhart commented 1 week ago

https://github.com/microsoft/vscode/issues/216834#issuecomment-2187461867

@mjbvz, if targeting HTML5, it should be if you don't use a YAML preamble, since the <docType> is first. To my knowledge, as long as a Document Type (before anything else) then <head> and <body> tag are present with character set defined, it's valid. All else is considered "unformatted" by the browser, so it decides the tag to utilize in its renderer, but remains valid.

mjbvz commented 1 day ago

The markdown is rendered to an html fragment that is then included on an html page. This means you're going to end up with:

<!DOCTYPE html>
<html lang="en">

<head>
    <!-- ... -->
</head>

<body>
    <!-- ... -->

    <!-- Begin VS Code markdown content  -->

    <!DOCTYPE markdown>

    <!-- Actual rendered MD .... -->

</body>

</html>

We don't render the markdown to a complete html file (we don't even have built-in support for preamble's). We target the most common case for markdown

If you a more specialized use case, you'll need to write tooling to support that. Closing this issue because it's out of scope of our builtin markdown support

RokeJulianLockhart commented 1 day ago

https://github.com/microsoft/vscode/issues/216834#issuecomment-2207470800

@mjbvz, makes sense. Does seem like there's something wrong with your parser if, for this specific tag, it only accepts it if solely the first letter is upper case. If it needed to be upper case, surely the entire tag would need be, not just the first letter.