> For AI agents: the complete documentation index is available at https://canary.gukhanmun.org/ko-KR/llms.txt, the full documentation bundle is available at https://canary.gukhanmun.org/ko-KR/llms-full.txt.

# HTML 변환

`html` 피처가 필요합니다(기본으로 켜짐).

## HTML 조각(fragment) 변환

```rust
use gukhanmun::{Builder, Preset};

let converter = Builder::with_preset(Preset::KoKr).build()?;
let output = converter.convert_html_fragment_to_string("<p>漢字</p>")?;
// → "<p>한자</p>"
```

Gukhanmun은 입력을 (완전한 문서가 아니라) HTML 조각으로 해석하고, 텍스트 노드와
속성 속의 한자를 변환하며, 모든 태그와 속성을 그대로 보존하면서 결과를
직렬화합니다.

## 항상 보존되는 요소

다음 요소는 결코 수정되지 않습니다:

- `<code>`, `<kbd>`, `<pre>`, `<samp>`
- `<script>`, `<style>`, `<textarea>`
- `translate="no"`를 가진 요소
- `<ruby>` 주해(annotation) 내용(`<rt>`, `<rp>`)

## 사용자 정의 보존 규칙

`builder.html_preserve_when`을 사용하여, 각 요소의 태그명과 속성을 받고 변환을
건너뛸 때 `true`를 반환하는 술어를 등록합니다:

```rust
builder.html_preserve_when(|tag, attrs| {
    // class "math"나 屬性 "data-no-hanja"를 가진 要素를 保存
    let has_math_class = attrs.get("class")
        .is_some_and(|c| c.split_whitespace().any(|cls| cls == "math"));
    let has_attr = attrs.contains_key("data-no-hanja");
    has_math_class || has_attr
});
```

`html_preserve_when`을 여러 번 호출하면 술어가 추가됩니다; `true`를 반환하는
술어가 하나라도 있으면 그 요소(와 그 후손)가 보존됩니다.
