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

Inline elements in image descriptions are flattened and stripped #423

Open
Feuermurmel opened this issue Feb 1, 2024 · 2 comments
Open
Labels
bug Something isn't working

Comments

@Feuermurmel
Copy link

Consider the following document:

![example](/url)

![*example*](/url)

![`example`](/url)

mdformat changes the document to this:

![example](/url)

![example](/url)

![](/url)

In the second case, the formatting is removed. In the third case, the formatted inline element is removed completely. This is surprising to me and the case of removing the inline element seems dangerous to me. I would have expected mdformat to not change this document.

I looked into the CommonMark specification (6.4 Images), which says that an image description can contain inline elements, but that they should be flattened to the plain text content of the elements when rendering to HTML.

This means that in the second case, some information is lost because the document could be rendered to an output format that supports styled image descriptions and in the third case, part of the text is lost.

My setup:

$ pip install mdformat
Collecting mdformat
  Downloading mdformat-0.7.17-py3-none-any.whl.metadata (8.7 kB)
Collecting markdown-it-py<4.0.0,>=1.0.0 (from mdformat)
  Using cached markdown_it_py-3.0.0-py3-none-any.whl.metadata (6.9 kB)
Collecting mdurl~=0.1 (from markdown-it-py<4.0.0,>=1.0.0->mdformat)
  Using cached mdurl-0.1.2-py3-none-any.whl (10.0 kB)
Downloading mdformat-0.7.17-py3-none-any.whl (28 kB)
Using cached markdown_it_py-3.0.0-py3-none-any.whl (87 kB)
Installing collected packages: mdurl, markdown-it-py, mdformat
Successfully installed markdown-it-py-3.0.0 mdformat-0.7.17 mdurl-0.1.2

I ran mdformat without arguments:

mdformat foo.md
Copy link

welcome bot commented Feb 1, 2024

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! 🎉

@hukkin hukkin added the bug Something isn't working label Feb 3, 2024
@hukkin
Copy link
Owner

hukkin commented Feb 3, 2024

Thanks for the issue!

The third case seems like a duplicate of #414

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants