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

Admonition title syntax is not consistent with other implementation #93

Closed
randomstuff opened this issue Jun 21, 2023 · 14 comments · Fixed by #94
Closed

Admonition title syntax is not consistent with other implementation #93

randomstuff opened this issue Jun 21, 2023 · 14 comments · Fixed by #94
Labels
bug Something isn't working

Comments

@randomstuff
Copy link

randomstuff commented Jun 21, 2023

Describe the bug

context

The admonition syntax is based on Python Markdown:

!!! danger "Don't try this at home"
    ...

expectation

I would expect the quotes to be absent from the output.

bug

With mdit-py-plugins, the quotes are present in the output:

image

Unexpected output generated by mdit-py-plugins (spurious quotes):

<div class="admonition danger"> <p class="admonition-title">"Don't try this at home"</p> <p>...</p> </div>

Moreover, the additional CSS classes are not supported either.

Changing the behavior might cause compatiblity issues with markdown-it-admon however.

problem

This is a problem for people migrating from Python Markdown.

Reproduce the bug

Create markdown file with:

!!! danger "Don't try this at home"
    ...

Create script

from markdown_it import MarkdownIt
from mdit_py_plugins.admon import admon_plugin

md_opts = {
    "html": True,
}

markdown_it_render = MarkdownIt("commonmark", md_opts).use(admon_plugin)

source = open("/dev/stdin", "rt").read()
res = markdown_it_render.render(source)
print(res)

Run:

python3 test.py < test.md

Output:

<div class="admonition danger">
<p class="admonition-title">&quot;Don't try this at home&quot;</p>
<p>...</p>
</div>

List your environment

  • Python 3.11.4
  • Debian Linux
  • markdown-it-py==3.0.0
  • mdit-py-plugins==0.4.0
@randomstuff randomstuff added the bug Something isn't working label Jun 21, 2023
@welcome
Copy link

welcome bot commented Jun 21, 2023

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! 🎉

@chrisjsewell
Copy link
Member

Pinging @KyleKing (who worked on this plugin 😄 )

@KyleKing
Copy link
Contributor

Thanks for reporting the bug. It may be straightforward to remove the outer quotes from the matched admonition title, and I'll separately take a look at the CSS classes since those seem pretty generic

@KyleKing
Copy link
Contributor

KyleKing commented Jun 21, 2023

I have a PR that should resolve the problem in: #94

I'll take a look at the HTML roles next

randomstuff pushed a commit to randomstuff/mdit-py-plugins that referenced this issue Jun 21, 2023
@randomstuff
Copy link
Author

For reference, here is a quick patch I made, probably redundant with yours.

@KyleKing
Copy link
Contributor

Got the HTML roles too 👍🏻

@chrisjsewell #94 is ready for review. I'm happy to split off the roles change in a separate PR. Let me know if there is anything I can add or remove otherwise!

@randomstuff
Copy link
Author

Moreover, the additional CSS classes are not supported either.

Some clarifications about this point.

This is the syntax documented in mkdocs-material. This implementation supports multiple token after !!! which are translated into CSS classes.

!!! info inline end "Lorem ipsum"

    Lorem ipsum dolor sit amet, consectetur
    adipiscing elit. Nulla et euismod nulla.
    Curabitur feugiat, tortor non consequat
    finibus, justo purus auctor massa, nec
    semper lorem quam in massa.

Which gives:

<div class="admonition info inline end"> <p class="admonition-title">Lorem ipsum</p> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor massa, nec semper lorem quam in massa.</p> </div>

@randomstuff
Copy link
Author

My PR attempts to provides this but introduces a breaking change for this reason.

@randomstuff
Copy link
Author

randomstuff commented Jun 21, 2023

This syntax is what is implemented in Python Markdown in practice (though not documented?):

>>> import re
>>> RE = re.compile(r'(?:^|\n)!!! ?([\w\-]+(?: +[\w\-]+)*)(?: +"(.*?)")? *(?:\n|$)')
>>> RE.match("!!! a b c d").groups()
('a b c d', None)
>>> RE.match('!!! a b c d   "zzzz"  ').groups()
('a b c d', 'zzzz')

randomstuff pushed a commit to randomstuff/mdit-py-plugins that referenced this issue Jun 21, 2023
randomstuff pushed a commit to randomstuff/mdit-py-plugins that referenced this issue Jun 21, 2023
randomstuff pushed a commit to randomstuff/mdit-py-plugins that referenced this issue Jun 21, 2023
@randomstuff
Copy link
Author

Notice in particuliar how the Python-Markdown implementation handles trailing "":

>>> RE.match('!!! a b c d   "Note: note about "foo""  ').groups()
('a b c d', 'Note: note about "foo"')

@KyleKing
Copy link
Contributor

I just saw your replies here. I think we should be able to avoid a breaking change if double quotes aren't present, but I'll need to check locally

@randomstuff
Copy link
Author

Kindly ping. Need help on this?

@KyleKing
Copy link
Contributor

The PR is done and awaiting review.

@chrisjsewell, when you have a chance, could you please review and release this change: #94?

@KyleKing
Copy link
Contributor

FYI: this change will be released in the next version of mdformat-admon regardless of the status of the PR (KyleKing/mdformat-admon@aa27baa)

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

Successfully merging a pull request may close this issue.

3 participants