Skip to main content

Module suggest

Module suggest 

Source
Expand description

Conservative nearest-match selection for “did you mean” diagnostics.

Several passes answer the same question: the user wrote an identifier that matches nothing — is one known name a plausible near-miss worth offering as a fix? This module owns the shared edit-distance metric, the selection rule, and the MOS0015 unknown-key diagnostic builder; callers supply their own candidate sets (reference labels, citation keys, #set targets, directive keyword arguments).

Functions§

edit_distance 🔒
Byte-level edit distance counting an adjacent transposition as one edit (optimal string alignment, the restricted Damerau-Levenshtein variant).
escape_string_content 🔒
Re-escape text so it can sit between the quotes of a .mos string literal. This inverts the parser’s \\, \", \n, \t, and \r escapes.
nearest_match 🔒
The single candidate that is a reasonable near-miss for unknown, if any.
portable_path_fix 🔒
Rewrite every \ in path to / when the result is a relative path that [resolve_relative] accepts. Returns None for a path with no \, and for rooted, drive-prefixed, or UNC forms, where the swap would change the path’s meaning.
unknown_key_diagnostic 🔒
Build the MOS0015 unknown-keyword-argument diagnostic shared by #set, #image, #figure, and #bibliography, attaching a fix replacing exactly the key token when one known key is a conservative near-miss.
unsafe_path_diagnostic 🔒
Build the MOS0049 unsafe-path diagnostic for a #image / #figure / #bibliography string argument, attaching a fix that rewrites the literal’s contents to the /-only spelling when portable_path_fix can produce one.