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

Wrong positive MD049 (emphasis style) with $$ math blocks #162

Closed
jannismain opened this issue May 21, 2023 · 9 comments
Closed

Wrong positive MD049 (emphasis style) with $$ math blocks #162

jannismain opened this issue May 21, 2023 · 9 comments
Labels
question Further information is requested

Comments

@jannismain
Copy link

In Markdown documents that include Mathjax formulas, defining math blocks like this is quite common:

# Heading

Blabla (*foo*)

$$
q^{'}_{i} = q^{'}_{i+1}
$$

Expected Behavior

No warning should be raised, as the document looks quite reasonable.

Actual Behavior

Running markdownlint-cli2 on this document raises a seemingly unrelated issue:

$ markdownlint-cli2 markdownlint-example.md
markdownlint-cli2 v0.5.1 (markdownlint v0.26.2)
Finding: markdownlint-example.md
Linting: 1 file(s)
Summary: 1 error(s)
markdownlint-example.md:6:6 MD049/emphasis-style Emphasis style should be consistent [Expected: asterisk; Actual: underscore]
@jannismain
Copy link
Author

So first I though it would just not handle the custom $$ block syntax correctly.

However, when slightly shortening the formula by removing the exponents (but leaving the subscripts!) like this:

# Heading

Blabla (*foo*)

$$
q_{i} = q_{i+1}
$$

the false positive MD049 warning doesn't appear:

$ markdownlint-cli2 markdownlint-example.md
markdownlint-cli2 v0.5.1 (markdownlint v0.26.2)
Finding: markdownlint-example.md
Linting: 1 file(s)
Summary: 0 error(s)

This leads me to believe that this might be a bug.

@nschonni
Copy link
Contributor

@DavidAnson
Copy link
Owner

There's kind of a lot going on here. Nick good to point out you shouldn't see this if you try using the VS Code extension because it implicitly includes a plug-in for parsing math blocks. CLI2 does not implicitly include plug-ins, so it thinks the content of the math block is normal Markdown. If you install and reference that plug-in in your scenario, this warning should go away. There are examples in the repo for how to do so.

What makes this scenario a little different is that MD049 does use the parser whereas the rule in the referenced issue does not. As I continue the migration to micromark, I will probably reference a similar plug-in implicitly so this scenario "just works" even in CLI2.

@DavidAnson DavidAnson added the question Further information is requested label May 21, 2023
@DavidAnson
Copy link
Owner

In conclusion, I would not consider this a bug assuming referencing the texmath plug-in suppresses the warning.

@jannismain
Copy link
Author

Thanks for the pointer towards the texmath plugin. With the texmath plugin enabled, MD049 is no longer raised.

For everybody experiencing the same behavior, I have created a gist that quickly outlines the problem and solution.

@DavidAnson
Copy link
Owner

Thanks!

@jannismain
Copy link
Author

jannismain commented May 21, 2023

With the configuration included in the gist linked above:

{
  "markdownItPlugins": [
    ["markdown-it-texmath"]
  ]
}

the CLI works as expected now. However, the vscode extension now acts up:

[8:59:32 PM] ERROR: Exception while linting with markdownlint-cli2:
Error: Cannot find module 'markdown-it-texmath'
Require stack:
...

I have installed the requirements globally

$ npm -g list         
/opt/homebrew/lib
...
+-- katex@0.16.7
+-- markdown-it-texmath@1.0.0
+-- markdownlint-cli2@0.5.1
...

Am I missing something here? Is it worth opening up another issue over at @DavidAnson/vscode-markdownlint

@jannismain jannismain reopened this May 21, 2023
@DavidAnson
Copy link
Owner

See DavidAnson/vscode-markdownlint#180

A local install of the plug-in (within the project as with other dependencies) should work for both scenarios.

@jannismain
Copy link
Author

That fixed it! Thanks! I have updated the gist to suggest a local installation to keep compatibility with vscode-markdownlint.

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

No branches or pull requests

3 participants