streetsidesoftware / vscode-spell-checker

A simple source code spell checker for code
https://streetsidesoftware.github.io/vscode-spell-checker/
Other
1.39k stars 124 forks source link

Change language in markdown code fences #242

Open gandalfsaxe opened 6 years ago

gandalfsaxe commented 6 years ago

Great extension! However I often make code fences in markdown, resulting in LOTS of false positive when vscode-spell-checker checks the code fence as if it was markdown code. Example:

# Some title
Bla bla this is markdown and all is good.

```latex
\usepackage[utf8]{inputenc}

which would result in warning on `usepackage` and `inputenc`. Here is a screenshot that shows the issue:

![image](https://user-images.githubusercontent.com/12127864/42728831-a846238a-87c4-11e8-92dd-cd9506424915.png)

The best solution would be to dynamically switch to the code fence language locally within the code fence.

The next-best solution would be to just ignore all content without code fences.
gandalfsaxe commented 6 years ago

As a workaround, I have manually enabled the latex dictionary for the folder :)

Jason3S commented 6 years ago

It is possible to ignore those sections:

For all file types:

    "cSpell.ignoreRegExpList": [
         "/^```(?:.|\\s)+?^```/mig"
    ],

To have it apply only to markdown:

"cSpell.languageSettings": [
        {
            "languageId": "markdown",
            "ignoreRegExpList": [
                "/^```(?:.|\\s)+?^```/mig"
             ]
        }
    ]
gandalfsaxe commented 6 years ago

Thanks, can confirm it works to ignore content in code fences 👍

  1. Any hope for locally applying dictionary in code fence according to code fence language?
  2. Any way of saying "Enable latex dict when editing markdown files"?
gandalfsaxe commented 6 years ago

For inspiration, prettier.io actually implemented detection of language in code fences: https://prettier.io/blog/2018/04/11/1.12.0.html#support-fenced-codeblock-lang-followed-by-attributes-4153-https-githubcom-prettier-prettier-pull-4153-by-ikatyang-https-githubcom-ikatyang

noraj commented 5 years ago

Wanted behavior for markdown:

The current behavior is a nightmare for people writing technical stuff.

Else it generate too much false positive:

Plaintext code block:

image

image

Inline code:

image

peixinshen commented 3 years ago

With regard to enable LaTeX dictionary in the markdown file, my workaround is to change the global setting in settings.json,

"cSpell.languageSettings": [
        {"languageId": "markdown",  "dictionaries": ["latex"]}
    ]
gauss256 commented 3 years ago

I've posted a solution here: https://github.com/streetsidesoftware/vscode-spell-checker/issues/357?_pjax=%23repo-content-pjax-container#issuecomment-898993398

It doesn't dynamically switch to the code fence language locally within the code fence, but it excludes spell checking in code blocks, which takes care of all the false positives in them.