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

MD033 flagging HTML tags in image alt text strings #579

Closed
nschonni opened this issue Sep 11, 2022 · 9 comments
Closed

MD033 flagging HTML tags in image alt text strings #579

nschonni opened this issue Sep 11, 2022 · 9 comments
Labels

Comments

@nschonni
Copy link
Contributor

https://dlaa.me/markdownlint/#%25m!%5BThe%20default%2C%20focused%2C%20and%20disabled%20%3Ctextarea%3E%20element%20in%20Firefox%2071%20and%20Safari%2013%20on%20Mac%20OSX%20and%20Edge%2018%2C%20Yandex%2014%2C%20Firefox%20and%20Chrome%20on%20Windows%2010.%5D(textarea_basic.png)
Since the alt tag doesn't get parsed as HTML, there shouldn't be a need to escape these.
Ran into this because i had been escaping the tags, but then running prettier would clean off the escaping because it was not needed.

Similar thing happens with link title strings, but that's probably a separate bug

@DavidAnson
Copy link
Owner

@nschonni
Copy link
Contributor Author

Hmm, I'm thinking it might be a Markdown-it bug then. If you run it through GitHub's parser or the remark parser like Prettier uses, its not treated as a literal

The default, focused, and disabled <textarea> element in Firefox 71 and Safari 13 on Mac OSX and Edge 18, Yandex 14, Firefox and Chrome on Windows 10.

@DavidAnson
Copy link
Owner

Toggling the "HTML" checkbox on that demo page opt into and out of this removal behavior.

Skimming the CommonMark specification, it's not clear to me that this scenario is directly addressed, so I think the parser is behaving consistently.

@nschonni
Copy link
Contributor Author

I filed something on Markdown-it, but looking at the spec https://spec.commonmark.org/0.30/#images it is light, but

Though this spec is concerned with parsing, not rendering, it is recommended that in rendering to HTML, only the plain string content of the image description be used. Note that in the above example, the alt attribute’s value is foo bar, not foo bar or foo bar. Only the plain string content is rendered, without formatting.

@rlidwka
Copy link

rlidwka commented Sep 12, 2022

Everything is parsed in alt, but only plain text is rendered. Consider ![foo *bar* baz]() - it's gonna lose asterisks (in cmark and in github version too).

I believe linter for commonmark syntax should flag any non-text, non-escape inside img tag, because it'll just get ignored by parsers. HTML is no exception there.

@nschonni
Copy link
Contributor Author

@nschonni
Copy link
Contributor Author

Found a relevant discussion commonmark/commonmark-spec#716 but there is no resolution right now

@DavidAnson
Copy link
Owner

Closing this based on my Sept 10 example and lack of agreement in the comments about whether this is reasonable.

@nschonni
Copy link
Contributor Author

OK, I'll ping this issue if there is a resolution on the CommonMark or Markdown-it issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants