For AI agents: the complete documentation index is available at https://canary.gukhanmun.org/llms.txt, the full documentation bundle is available at https://canary.gukhanmun.org/llms-full.txt, and this page is available as Markdown at https://canary.gukhanmun.org/guide/python/directives.md.

Directives

Directives adjusts how selected readings are presented. It does not add dictionary entries or choose a different reading. Its three sequences contain literal hanja forms, rather than glob patterns or Python callbacks.

from gukhanmun import Converter, DictionaryEntry, Directives, MapDictionarySource

converter = Converter(
    dictionaries=[MapDictionarySource([DictionaryEntry("漢字", "한자")])],
    directives=Directives(require_hanja=["漢字"]),
)
assert converter.convert("漢字") == "한자(漢字)"

Rules operate on conversion annotations. Add the whole term to a dictionary if it needs to be recognized as a single unit. Dictionary identity metadata can mark an alternate spelling as a reviewed alias of a canonical form. A literal rule for that canonical form then also applies to the alias.

Combining directives with rendering

FieldEffect
require_hanjaKeep hanja visible, including in hangul-only mode
require_hangulInclude a hangul gloss, including in original mode
skip_annotationUse only the active mode's primary text

For ORIGINAL, a required hangul reading becomes a gloss:

from gukhanmun import Converter, DictionaryEntry, Directives, MapDictionarySource, RenderMode

converter = Converter(
    dictionaries=[MapDictionarySource([DictionaryEntry("漢字", "한자")])],
    rendering=RenderMode.ORIGINAL,
    directives=Directives(require_hangul=["漢字"]),
)
assert converter.convert("漢字") == "漢字(한자)"

skip_annotation suppresses parentheses and ruby rather than preserving the input verbatim. Modes with hangul as their primary text keep the reading; modes with hanja as their primary text keep hanja. To leave an HTML subtree unconverted, use HTML preservation rules.

One form may appear in both require_hanja and require_hangul. skip_annotation suppresses annotation rendering even when a requirement is also present. Input sequences are copied into immutable tuples at construction.