Documentation
¶
Overview ¶
Package spellcheck provides dictionary-backed spell checking for the composer.
Dictionaries follow the Hunspell .dic format (word list, optional /flags per line). Affix rules are ignored: each base form is added to a flat word set. Dictionaries are downloaded from the wooorm/dictionaries GitHub repository on demand.
Index ¶
- Constants
- Variables
- func DictInstalled(lang string) bool
- func DictPath(lang string) (string, error)
- func DictsDir() (string, error)
- func Download(lang string) (string, error)
- func EnsureDefault() (string, error)
- func Highlight(text string, c *Checker, skipLine int) string
- func IsCheckable(word string) bool
- type Checker
- type Token
Constants ¶
const DefaultLanguage = "en"
DefaultLanguage is the language code installed automatically the first time the composer opens.
Variables ¶
var DictURLTemplate = "https://raw.githubusercontent.com/wooorm/dictionaries/main/dictionaries/%s/index.dic"
DictURLTemplate is the URL used to fetch Hunspell .dic files. It is a variable to allow tests and the CLI to override the source.
Functions ¶
func DictInstalled ¶
DictInstalled reports whether the dictionary for lang exists on disk.
func Download ¶
Download fetches the dictionary for lang from DictURLTemplate and writes it atomically to the dicts directory.
func EnsureDefault ¶
EnsureDefault downloads the default English dictionary if it is not already installed and returns the language code that is available.
func Highlight ¶
Highlight walks rendered text and wraps misspelled words in a red dotted underline. ANSI sequences already present in the input are preserved.
The text is processed line by line. The line at index skipLine is left untouched — pass -1 to highlight every line.
func IsCheckable ¶
IsCheckable returns true when the token looks like a natural-language word worth spell-checking. URLs, email-like fragments, numbers, single letters, and all-uppercase short tokens (likely acronyms) are skipped.
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker holds a loaded word set and reports whether tokens are known.
func NewChecker ¶
func NewChecker() *Checker
NewChecker returns an empty checker. Load must be called before Check returns useful results.
func (*Checker) Check ¶
Check reports whether the word is recognised. Words shorter than 2 runes, numeric, or containing only punctuation are always treated as correct. Words that contain letter runes outside the loaded dictionary's alphabet (e.g. Cyrillic text against an English dictionary, or accented characters not present in the dictionary's base forms) are also treated as correct — we have no signal to judge them.
func (*Checker) LoadLang ¶
LoadLang loads the dictionary for the given language code from the configured dicts directory.