vscode-spell-checker icon indicating copy to clipboard operation
vscode-spell-checker copied to clipboard

Change language in markdown code fences

Open gandalfsaxe opened this issue 6 years ago • 7 comments

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

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 avatar Jul 14 '18 22:07 gandalfsaxe

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

gandalfsaxe avatar Jul 14 '18 22:07 gandalfsaxe

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"
             ]
        }
    ]

Jason3S avatar Jul 21 '18 11:07 Jason3S

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 avatar Jul 22 '18 17:07 gandalfsaxe

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

gandalfsaxe avatar Aug 10 '18 21:08 gandalfsaxe

Wanted behavior for markdown:

  • code block: follow the language declared
  • code block: if not language is declared (so it is plaintext), disable spellcheck by default or add an option to do it
  • inline code: disable spellcheck by default or add an option to do it

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

noraj avatar Jan 13 '19 16:01 noraj

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"]}
    ]

peixinshen avatar May 05 '21 18:05 peixinshen

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.

gauss256 avatar Aug 15 '21 04:08 gauss256