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

Render html tags inside img alt as their original text #979

Merged
merged 1 commit into from Dec 6, 2023
Merged

Conversation

rlidwka
Copy link
Member

@rlidwka rlidwka commented Dec 3, 2023

See discussion in #896.

Spec is not clear on how to handle this. Three variations exist:

$ echo '![text <textarea> text](image.png)' | /home/user/commonmark.js/bin/commonmark
<p><img src="image.png" alt="text <textarea> text" /></p>

$ echo '![text <textarea> text](image.png)' | /home/user/cmark/build/src/cmark
<p><img src="image.png" alt="text &lt;textarea&gt; text" /></p>

$ echo '![text <textarea> text](image.png)' | /home/user/.local/bin/commonmark
<p><img src="image.png" alt="text  text" /></p>

Discussion in commonmark spec issue is inconclusive.

In addition to that, there's a small inconsistency in markdown-it output (with html option on or off there will be different result), which is going to raise questions.

This is not necessarily a final solution (still waiting on spec), but the following change seems reasonable:

Prior to this commit:

  • when HTML tags are enabled, tags were removed (as in Haskell version)
  • when HTML tags are disabled, tags were escaped (as in C version)

After this commit:

  • tags will be escaped (as in C version) regardless of HTML flag

Going with option 2 here. Not option 3, because people asked about this. Not option 1, because we escape <> inside attributes.

This commit also renders hardbreak token as newline - this is same as in commonmark reference implementation at this moment (not defined in spec).

Spec is not clear on how to handle this. Three variations exist:

```
$ echo '![text <textarea> text](image.png)' | /home/user/commonmark.js/bin/commonmark
<p><img src="image.png" alt="text <textarea> text" /></p>

$ echo '![text <textarea> text](image.png)' | /home/user/cmark/build/src/cmark
<p><img src="image.png" alt="text &lt;textarea&gt; text" /></p>

$ echo '![text <textarea> text](image.png)' | /home/user/.local/bin/commonmark
<p><img src="image.png" alt="text  text" /></p>
```

Prior to this commit:
 - when HTML tags are enabled, tags were removed (as in Haskell version)
 - when HTML tags are disabled, tags were escaped (as in C version)

After this commit:
 - tags will be escaped (as in C version) regardless of HTML flag

+ render hardbreaks as newlines, same as cmark
@puzrin puzrin merged commit d9885ba into master Dec 6, 2023
2 checks passed
@puzrin puzrin deleted the fix-896 branch December 8, 2023 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants