codespell-project / codespell

check code for common misspellings
GNU General Public License v2.0
1.84k stars 470 forks source link

Unable to add inline comments for markdown documents #3396

Closed ssbarnea closed 4 months ago

ssbarnea commented 4 months ago

I tried to make use of inline ignore feature supposely introduced by https://github.com/codespell-project/codespell/pull/2400 inside Markdown documents but I found no way to do so.

A simple search on https://sourcegraph.com/search?q=context:global+lang:Markdown+codespell:ignore&patternType=keyword&sm=0 shows that nobody ever used the "codespell:ignore" inside a markdown document.

DimitriPapadopoulos commented 4 months ago

You need to add comments to your Markdown documents, but Markdown has not comments. The proper search keywords would be Markdown and comment: https://www.google.com/search?q=Markdown+comment

ssbarnea commented 4 months ago

@DimitriPapadopoulos The first google link towards SO contains lots of comments that can be used in Markdown, being supported by most important libraries, but none is supported by codespell. I tried all from there before opening the issue.

DimitriPapadopoulos commented 4 months ago

Edit: the 1st sentence was wrong: Wait, do you expect an isolated "codespell:ignore" to work by itself? You need "codespell:ignore word_to_ignore".

Otherwise, codespell does not need to support Markdown comments, it doesn't even parse Markdown as such — it just reads and interprets all files as a stream of text.

Finally, while Markdown doesn't have comments as such, the first Google link indeed explains how to abuse Markdown to add comments:

this is not a comment [//]: # ( this is a comment )

From there, just such a Markdown "comment" to add "codespell:ignore". For example:

$ cat file1.md
abandonned [//]: # ( )
$ 
$ codespell file1.md
file1.md:1: abandonned ==> abandoned
$ 
$ cat file2.md
abandonned [//]: # ( codespell:ignore abandonned )
$ 
$ codespell file2.md
$ 
DimitriPapadopoulos commented 4 months ago

Actually, it looks like Markdown does not have inline comments, they need to be on a line by themselves. For example,:

[//]: # ( this is a comment )

is not rendered, but

this is not a comment [//]: # ( this is a comment )

is rendered as:

this is not a comment [//]: # ( this is a comment )

Eventually, this is not a codespell issue. You need a way to add inline comments in a Makrdown file, but I don't think that's possible.

ssbarnea commented 4 months ago

<!-- .. --> is yet another way to add them.

DimitriPapadopoulos commented 4 months ago

Indeed, this:

this is not a comment <!-- this is a comment -->

appears to be rendered as:

this is not a comment
DimitriPapadopoulos commented 4 months ago

So you have your answer:

$ cat file1.md 
abandonned <!-- -->
$ 
$ codespell file1.md 
file1.md:1: abandonned ==> abandoned
$ 
$ cat file2.md 
abandonned <!-- codespell:ignore -->
$ 
$ codespell file2.md 
$