markdownlint icon indicating copy to clipboard operation
markdownlint copied to clipboard

Investigate generalized support for skipping block/inline content via regular expression (or similar)

Open XhmikosR opened this issue 5 years ago • 8 comments

Hey, @DavidAnson!

I have a WIP branch in https://github.com/twbs/bootstrap/compare/master-xmr-markdownlint where I'm trying to add markdownlint through markdownlint-cli.

It seems I'm hitting a few issues and I'm not sure how to proceed. I mean, most are due to our mix of Hugo shortcodes, but I'm reaching out in case you have any suggestions or if any improvements can be made.

CI link so make things a little easier

site/content/docs/4.3/components/collapse.md:87 MD046/code-block-style Code block style [Expected: fenced; Actual: indented]

This seems a false positive since the block is inside a Hugo shortcode ({{< example >}}). If I change this to consistent it no longer complains. Or if I just remove the newline.

 site/content/docs/4.3/getting-started/introduction.md:121 MD034/no-bare-urls Bare URL used [Context: "https://twitter.com/{{<"]

This is also a false positive because the URLs also have a hugo function (- Follow [@getbootstrap on Twitter](https://twitter.com/{{< param twitter >}}).). I'm not sure if you can do anything about this

  1. Is there any way to ignore specific blocks without using inline comments? For example, say I want to skip all {{< markdown >}} blocks.

XhmikosR avatar Jan 24 '20 16:01 XhmikosR

I’ll try to respond to these as I have time. I’m on my phone at the moment, but I think I can help with the first question.

The markdown-it parser does not recognize Hugo syntax; the line it reports appears to be the first that is indented by four spaces which represents a code block. You can see this by pasting the content here: https://markdown-it.github.io/

What I think you want is for these Hugo blocks to be treated as code and in order to do that you might have the best luck with a custom markdown-it plugin. The last four test cases in this project show how to reference plug-ins. A quick search of npm did not turn up an existing one, but maybe you can find one or thinking about adding one.

DavidAnson avatar Jan 24 '20 16:01 DavidAnson

For the second issue, the content as it exists does contain a bare link according to CommonMark rules: https://markdown-it.github.io/#md3=%7B%22source%22%3A%22Follow%20%5B%40getbootstrap%20on%20Twitter%5D%28https%3A%2F%2Ftwitter.com%2F%7B%7B%3C%20param%20twitter%20%3E%7D%7D%29.%22%2C%22defaults%22%3A%7B%22html%22%3Afalse%2C%22xhtmlOut%22%3Afalse%2C%22breaks%22%3Afalse%2C%22langPrefix%22%3A%22language-%22%2C%22linkify%22%3Atrue%2C%22typographer%22%3Atrue%2C%22_highlight%22%3Atrue%2C%22_strict%22%3Afalse%2C%22_view%22%3A%22html%22%7D%7D

In this case, I’m not sure a custom plug-in would help because the scenario is not recognizing the new syntax, but modifying an existing one.

Would it be possible for you to lint these files after the Hugo tags had been applied?

DavidAnson avatar Jan 24 '20 16:01 DavidAnson

I think the answer to the third question is a custom plug-in for Hugo.

For questions number one and number three, I think a custom plug-in that understands Hugo syntax will do what you want. For question number two, I’m not sure.

DavidAnson avatar Jan 24 '20 17:01 DavidAnson

So I guess it boils down to I'd there's a way to skip some snippets. Does this sound like a good addition?

On Fri, Jan 24, 2020, 19:00 David Anson [email protected] wrote:

I think the answer to the third question is a custom plug-in for Hugo.

For questions number one and number three, I think a custom plug-in that understands Hugo syntax will do what you want. For question number two, I’m not sure.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DavidAnson/markdownlint/issues/249?email_source=notifications&email_token=AACVLNOZBH2FDF6W5OPE2SDQ7MNDVA5CNFSM4KLIOUXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ3NUXA#issuecomment-578214492, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACVLNJYYVVRF5FKMVFEY4DQ7MNDVANCNFSM4KLIOUXA .

XhmikosR avatar Feb 07 '20 23:02 XhmikosR

Are you suggesting generalized support for skipping certain kinds of block or inline content via regular expression or something? That could have some uses and would probably be sufficient for your purposes here. I’d worry about coming up with something that’s powerful enough without being too complicated, but I’d be happy to look into this for the next release.

DavidAnson avatar Feb 08 '20 00:02 DavidAnson

Yup, I guess this would solve any issues for our use case and similar ones. Not sure how hard it'll be to implement :)

XhmikosR avatar Feb 11 '20 14:02 XhmikosR

@XhmikosR, is this still relevant?

DavidAnson avatar Aug 05 '23 21:08 DavidAnson

@DavidAnson sorry for the late reply. Yes, this would help us a lot since we still need to exclude Hugo-specific blocks. It's been a while since I last ran Markdownlint against our repo, though.

XhmikosR avatar Dec 17 '23 15:12 XhmikosR