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/rendering.md.

Rendering modes

rendering controls how a recognized word and its reading appear. The table shows 漢字 with a dictionary reading of 한자, without homophone or directive marks:

RenderModePlain-text output
HANGUL_ONLY (default)한자
HANGUL_HANJA_PARENS한자(漢字)
HANJA_HANGUL_PARENS漢字(한자)
RUBY_ON_HANGUL한자(漢字)
RUBY_ON_HANJA漢字(한자)
ORIGINAL漢字
from gukhanmun import Converter, DictionaryEntry, MapDictionarySource, RenderMode

source = MapDictionarySource([DictionaryEntry("漢字", "한자")])
converter = Converter(
    dictionaries=[source],
    rendering=RenderMode.HANGUL_HANJA_PARENS,
)
assert converter.convert("漢字") == "한자(漢字)"

Ruby markup

Ruby modes produce <ruby> elements in HTML and Markdown where inline markup is allowed. In plain text, and in text-only HTML elements such as <title> and <option>, they fall back to parentheses.

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

converter = Converter(
    dictionaries=[MapDictionarySource([DictionaryEntry("漢字", "한자")])],
    rendering=RenderMode.RUBY_ON_HANJA,
)
assert converter.convert("<p>漢字</p>", format=InputFormat.HTML) == (
    "<p><ruby>漢字<rp>(</rp><rt>한자</rt><rp>)</rp></ruby></p>"
)

RUBY_ON_HANGUL uses hangul as the base and hanja inside <rt> instead. The <rp> elements provide parentheses for browsers without ruby support.

Annotating only hanja runs

Pass annotation_granularity=AnnotationGranularity.HANJA_RUN to Converter() independently of rendering. For example, in RenderMode.HANGUL_HANJA_PARENS mode, 汽車길 becomes 기찻(汽車)길. AnnotationGranularity.WORD is the default and remains the fallback when the selected reading cannot be split uniquely. The resolved choice is available at converter.options.annotation_granularity.

Omitting dictionary-required hanja

Pass ignore_dictionary_required_hanja=True to Converter() to omit hanja glosses required only by dictionary entries in RenderMode.HANGUL_ONLY. The default is False. Homophone glosses, explicit directives, and recognized source glosses are unchanged. Read the configured value from converter.options.ignore_dictionary_required_hanja.

Original text with a gloss

ORIGINAL keeps hanja and adds a reading when an annotation carries a require_hangul mark. Homophone disambiguation alone does not add a reading in this mode. original_gloss chooses parentheses or ruby for those readings:

from gukhanmun import (
    Converter, DictionaryEntry, InputFormat, MapDictionarySource,
    OriginalGloss, RenderMode,
)

converter = Converter(
    dictionaries=[MapDictionarySource([
        DictionaryEntry("漢字", "한자", require_hangul=True),
    ])],
    rendering=RenderMode.ORIGINAL,
    original_gloss=OriginalGloss.RUBY,
)
assert converter.convert("漢字", format=InputFormat.HTML) == (
    "<ruby>漢字<rp>(</rp><rt>한자</rt><rp>)</rp></ruby>"
)
assert converter.convert("漢字") == "漢字(한자)"

OriginalGloss.PARENS is the default. original_gloss affects only RenderMode.ORIGINAL; it does not select the main rendering mode.

Hanja variant sets

A hanja character can have several variant spellings. Recognition of supported variants is always enabled. hanja_variant_set controls the spelling emitted after recognition by modes that retain hanja; it does not choose a dictionary or a reading.

from gukhanmun import Converter, HanjaVariantSet, RenderMode

converter = Converter(
    rendering=RenderMode.ORIGINAL,
    hanja_variant_set=HanjaVariantSet.SHINJITAI,
)
HanjaVariantSetOutput spelling
AS_DICTIONARY (default)Keep the spelling selected by the dictionary
SHINJITAIJapanese Joyo kanji new forms
KANXIPrefer traditional and compatibility-folded forms
SIMPLIFIEDUse the first Unicode kSimplifiedVariant mapping where available
ASAHIMOJIShinjitai plus Gukhanmun's verified Asahi mappings