antonWetzel / typst-languagetool

LanguageTool Integration for Typst for spell and grammer check
MIT License
37 stars 9 forks source link

Add support for custom dictionaries #5

Closed Skadic closed 10 months ago

Skadic commented 10 months ago

This PR adds the -w/--dictionary flag, which allows specifying a dictionary file. The dictionary file contains one word on each line. These words are ignored when LanguageTool reports misspellings. Example dictionary file:

alowed
woords
go-here

If LanguageTool reports the words alowed, woords or go-here as misspellings, they are ignored and not reported.

antonWetzel commented 10 months ago

Thanks for the contribution.

A few things before I can merge this

UTF-8 Bounds

let ctx = &m.context;
let mut chars = ctx.text.char_indices();
let start = chars.nth(ctx.offset).map_or(0, |(idx, _)| idx);
let end = chars.nth(ctx.length.wrapping_sub(1)).map_or(ctx.text.len(), |(idx, _)| idx);
let word = &ctx.text[start..end];
Skadic commented 10 months ago

Thanks for your answer! I changed the code accordingly.

On another note, I think I found a bug. Should I fix it here or make a new PR?

antonWetzel commented 10 months ago

Is merged, thanks for the help. For the bug I prefer a separate issue.