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

How to ignore code snippets in markdown files? #206

Closed
limorl opened this issue Mar 30, 2020 · 5 comments
Closed

How to ignore code snippets in markdown files? #206

limorl opened this issue Mar 30, 2020 · 5 comments

Comments

@limorl
Copy link

limorl commented Mar 30, 2020

I'm using cspell to spell check all the .md files in our repo.
I want to ignore the shell script code snippets within sh and delimiters.

I'm using ignoreRegExpList as follows:

"ignoreRegExpList": [
        "/```sh(.*?)```/gs",        // shell script
        ".*[.]azurewebsites[.]net", // websites
        "//.*[.](jpg|png)/ig",      // image names
        "/\/.*?\\s/ig"              //file path
    ],

All pattern matches are ignored, except for the first one for the shell code snippets.

@Jason3S
Copy link
Collaborator

Jason3S commented Apr 3, 2020

You have a few options:

One of them is to use comments:

  <!--- cSpell:disable -->
  ``` sh
  $ ls -alF
  ```
  <!--- cSpell:enable -->

The <!--- --> comments will be hidden.

The other option is to fix the regex:

    "ignoreRegExpList": [
        "/(```+)\\s?sh[\\s\\S]+?\\1/g",  // shell script code block
        ....
    ]

@limorl
Copy link
Author

limorl commented Apr 5, 2020

Thanks @Jason3S !
That regex worked for me. I wanted to to avoid using 'cSpell:disable'.

What I don't understand is why the original regex I used didn't work. I tested it with https://regex101.com/ (js regex) and it worked.

@Jason3S
Copy link
Collaborator

Jason3S commented Apr 6, 2020

(.*?) won't match across line boundaries.
[\s\S] will match all spaces and non-space characters, meaning it matches everything.

@Jason3S Jason3S added the FAQ label Apr 6, 2020
@limorl
Copy link
Author

limorl commented Apr 6, 2020

Thanks @Jason3S!! I thought the /s modifier takes care of that....
But I've just realized my mistake - I used the PHP flavor instead of the JavaScript one.
Many thanks!

image

br3ndonland added a commit to br3ndonland/dotfiles that referenced this issue Jul 2, 2020
Configure VSCodium code-spell-checker cspell.json to ignore Markdown
code blocks

Regex source (updated for code languages other than shell):
streetsidesoftware/cspell#206

Instructions for configuring code-spell-checker:
https://github.com/streetsidesoftware/cspell/tree/master/packages/cspell

Note that extra backslashes are required for JavaScript. To match
patterns with online regex checkers like regex101.com and regexr.com,
remove the extra backslashes: /(```+)\s?[a-z][\s\S]+?\1/g

developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
br3ndonland added a commit to br3ndonland/dotfiles that referenced this issue Jul 3, 2020
Configure VSCodium code-spell-checker cspell.json to ignore Markdown
code blocks

Regex source (updated for code languages other than shell):
streetsidesoftware/cspell#206

Instructions for configuring code-spell-checker:
https://github.com/streetsidesoftware/cspell/tree/master/packages/cspell

Note that extra backslashes are required for JavaScript. To match
patterns with online regex checkers like regex101.com and regexr.com,
remove the extra backslashes: /(```+)\s?[a-z][\s\S]+?\1/g

developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
br3ndonland added a commit to br3ndonland/dotfiles that referenced this issue Nov 6, 2020
Configure VSCodium code-spell-checker cspell.json to ignore Markdown
code blocks

Regex source (updated for code languages other than shell):
streetsidesoftware/cspell#206

Instructions for configuring code-spell-checker:
https://github.com/streetsidesoftware/cspell/tree/master/packages/cspell

Note that extra backslashes are required for JavaScript. To match
patterns with online regex checkers like regex101.com and regexr.com,
remove the extra backslashes: /(```+)\s?[a-z][\s\S]+?\1/g

developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
@Jason3S Jason3S changed the title Fail to ignore bash/shell code snippets in markdown file How to ignore code snippets in markdown files? Apr 6, 2022
@Jason3S Jason3S closed this as completed Apr 6, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 7, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants