[GH-ISSUE #197] Enable linting code blocks in Markdown content with external tools like eslint and flake8 #171

Closed
opened 2026-03-03 01:24:21 +03:00 by kerem · 5 comments
Owner

Originally created by @proofit404 on GitHub (Jun 12, 2019).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/197

Hi, thanks for an awesome package!

I wonder if there is any possibility to integrate somehow markdownlint with external tools like eslint, flake8 or rubocop to lint code examples written in the markdown document?

No pressure at all, I'm just asking if there is an internal API available I can use to write such plugins myself.

Best regards, Artem.

Originally created by @proofit404 on GitHub (Jun 12, 2019). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/197 Hi, thanks for an awesome package! I wonder if there is any possibility to integrate somehow `markdownlint` with external tools like `eslint`, `flake8` or `rubocop` to lint code examples written in the markdown document? No pressure at all, I'm just asking if there is an internal API available I can use to write such plugins myself. Best regards, Artem.
kerem 2026-03-03 01:24:21 +03:00
Author
Owner

@DavidAnson commented on GitHub (Jun 12, 2019):

Yes, that should be possible!

There are examples of calling the markdownlint API directly, as well as from Grunt and Gulp in the README: https://github.com/DavidAnson/markdownlint/blob/master/README.md#usage

If you can get the other tool(s) to flag chunks of Markdown content they encounter, you can lint that as strings input like in the examples above.

<!-- gh-comment-id:501349869 --> @DavidAnson commented on GitHub (Jun 12, 2019): Yes, that should be possible! There are examples of calling the `markdownlint` API directly, as well as from Grunt and Gulp in the README: https://github.com/DavidAnson/markdownlint/blob/master/README.md#usage If you can get the other tool(s) to flag chunks of Markdown content they encounter, you can lint that as `strings` input like in the examples above.
Author
Owner

@DavidAnson commented on GitHub (Jun 12, 2019):

Oh, wait, you are asking about the reverse! That would take a bit of work on my part. I’ll look into this for a future release. Thanks!

<!-- gh-comment-id:501350631 --> @DavidAnson commented on GitHub (Jun 12, 2019): Oh, wait, you are asking about the reverse! That would take a bit of work on my part. I’ll look into this for a future release. Thanks!
Author
Owner

@proofit404 commented on GitHub (Jun 12, 2019):

Cool! Thanks!

<!-- gh-comment-id:501494961 --> @proofit404 commented on GitHub (Jun 12, 2019): Cool! Thanks!
Author
Owner

@DavidAnson commented on GitHub (Jul 31, 2019):

I realized the best way to do this was with a custom rule (vs. modifying the library as I'd first considered). So I wrote a custom rule example that runs ESLint against any JavaScript code fences in Markdown. There's a lot more this rule could do (and I may expand upon it in the future), but it shows how to accomplish the task in a reasonable manner and you should be able to translate it to other tools pretty easily. Hope it helps!

<!-- gh-comment-id:516711336 --> @DavidAnson commented on GitHub (Jul 31, 2019): I realized the best way to do this was with a custom rule (vs. modifying the library as I'd first considered). So I wrote a custom rule example that runs ESLint against any JavaScript code fences in Markdown. There's a lot more this rule could do (and I may expand upon it in the future), but it shows how to accomplish the task in a reasonable manner and you should be able to translate it to other tools pretty easily. Hope it helps!
Author
Owner

@DavidAnson commented on GitHub (Jul 31, 2019):

Direct link from the commit above: github.com/DavidAnson/markdownlint@4d11e60cfe/test/rules/lint-javascript.js

<!-- gh-comment-id:516711730 --> @DavidAnson commented on GitHub (Jul 31, 2019): Direct link from the commit above: https://github.com/DavidAnson/markdownlint/blob/4d11e60cfe2cc50e36445bb1aaaf209ea063845e/test/rules/lint-javascript.js
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#171
No description provided.