-
-
Notifications
You must be signed in to change notification settings - Fork 247
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
Using bold in italics breaks italic markdown #1775
Comments
I wouldn't say this is a bug per se, but is currently expected. The question is whether we can adjust the rules in a sane and meanifulway without causing other side-effects. Now, I'm not saying this won't be fixed, but we'd need to be careful. Python Markdown fundamentally handles its rules different than other parsers. Some will gather all rules recursively as they are passed, some will execute all I'll give the TL;DR here:
Why is this not a bug?Historically, Python Mardown implemented bold and italic with simple regex. They just gobbled up text between the two tokens and called it a day. Ours improved upon that. Some intelligence was added to prevent some tokens from starting new spans, like (
The first
Such rules are stated in the docs. We do have some special cases, I don't recall them all off the top of my head, but IIRC they are all
Changes to this behavior would be considered an enhancement, and only if we can sanely do it without breaking other behavior. What do I do in these cases?Normally, I do not mix bold and italic in complex ways. I would have intuitively done your workaround.
But I think BetterEm should handle this case!That is a fair argument, but we'd have to come up with a sane way to handle this as the current implementation is just a series of complex regex. How do we identify this case and capture it with regex? Is there some sane regex rule we can inject that would catch this case and do exactly what we'd like it to do? Maybe some rule that only matches a single How do others parsers do this?Well, some may actually parse all rules one pass, they may use not regex rules are more flexible, unlike Python Markdown that generally applies regex rules in multiple passes on each paragraph. Can't we do something similar as other parsers?Well, maybe. We could completely re-write BetterEm to not use regex. |
Further thinking out loud. The one issue with the Python Markdown parser, particularly with using the inline regex rules, is you have to get all cases resolved in one pass. You can get around this by creating multiple plugin insertions (which we do use), but we are still using basic regex rules in all these cases, and that makes them limited. There is a tradeoff between adding some rules as opposed to being completely relaxed. I believe a more recursive approach is probably the way to handle such cases, and the way most parsers probably do this. |
We could actually just tokenize all As this is an enhancement, it won't take the same priority as a bug, but I do think it is worth exploring. |
@facelessuser Thanks for the in-depth explanation and considering the improvement 👍 |
Potential fix for this issue: >>> import markdown
>>> markdown.markdown('*(i.e. **Tools** > **Board** > **ESP32 Arduino** > `<board>`).*', extensions=['pymdownx.betterem'])
'<p><em>(i.e. <strong>Tools</strong> > <strong>Board</strong> > <strong>ESP32 Arduino</strong> > <code><board></code>).</em></p>' In short, I've added a case to favor the ideal case ( |
Description
I am running into a bug, similar to this discussion (squidfunk/mkdocs-material#2913 (comment)), where implementing a bold styling breaks the italics. However, it isn't an issue in reverse (italics in bold):
I believe I am using the latest release of the mkdocs-material theme 8.4.0, as the issue mentioned in the discussion is fixed:
I found a workaround to the problem by using underscores (
_
) instead of astericks (*
):Minimal Reproduction
Issue:
(i.e. Tools > Board > ESP32 Arduino >
<board>
).Test 1:
Something italic in a bold statement.
Test 2:
Something bold in an italic statement.
Workaround:
Something bold in an italic statement.
Generic example:
I'm italic and bold I am just bold.
I'm bold and italic! I am just italic.
Version(s) & System Info
The text was updated successfully, but these errors were encountered: