elijah-potter / harper

The Grammar Checker for Developers
https://writewithharper.com
Apache License 2.0
884 stars 23 forks source link

feat: harper should support "link plurals" in markdown #187

Open fisherdarling opened 5 days ago

fisherdarling commented 5 days ago

I'm calling a "link plural" a markdown structure in the form:

[`Span`]s

Where some link, with or without formatting, is followed by some other characters (usually a pluarl).

Right now, harper lints on the s as a separate entity (from just dogfood).

 118 │ /// Converts a set of byte-indexed [`Span`]s to char-index Spans, in-place.
     │                                            ┬  
     │                                            ╰── Did you mean to spell “s” this way?

We should add some kind of unwrapping of markdown structs so that harper only sees Spans in the above and can properly lint on it.

elijah-potter commented 5 days ago

Harper actually is unwrapping the Markdown structs. In the case of inline code blocks, they're marked as Tokenkind::Unlintable.It might be best to add a special case. If there is a "misspelled word" immediately after an unlintable token (without a space separating them), we may simply expand the unlintable token to include it.

Thoughts?

fisherdarling commented 1 day ago

In my local tests of the lexer, I saw that the braces are converted into punctuation nodes.

So: Punctuation, Unlintable, Punctuation, Text('s'). I think pulldown_cmark doesn't consider that a link, and therefore treats the braces as punctuation?

But in any case, that's an interesting idea. I was originally thinking of expanding on the markdown post processors to look for the pattern of [, Unlintable, ], non-space-text. Then replace the tokens with Unlintable + non-space-text.

I think you're advocating for doing that when a misspelled word is discovered. If we see a misspelled word, look at the previous tokens and try to construct a new word. That feels a bit less hacky than modifying the incoming token stream... I'll try to implement that first and see what it looks like.

Thanks!

elijah-potter commented 1 day ago

I'm loving your thought process. Keep us updated on what you end up trying.