> 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 처리

`convert()`에 형식으로 `"text/html"`을 넘깁니다:

```ts twoslash
import { load } from "@gukhanmun/wasm";
import { stdictFst } from "@gukhanmun/stdict-fst";

const g = await load({ dictionaries: [await stdictFst()] });

console.log(g.convert("<p>漢字</p>", "text/html"));
// → <p>한자</p>
```

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

## 항상 보존되는 요소

다음 요소와 그 후손은 결코 수정되지 않습니다:

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

## CSS 클래스로 요소 보존

특정 클래스를 가진 요소 안의 변환을 건너뛰려면 `html.preserveClasses`를
사용합니다:

```ts twoslash
import { load } from "@gukhanmun/wasm";
import { stdictFst } from "@gukhanmun/stdict-fst";
// ---cut-before---
const g = await load({
  dictionaries: [await stdictFst()],
  html: {
    preserveClasses: ["math", "no-translate"],
  },
});

const html = `
  <p>漢字</p>
  <span class="math">漢字</span>
`;
console.log(g.convert(html, "text/html"));
// → <p>한자</p>
//   <span class="math">漢字</span>   ← 保存됨
```

## 속성으로 요소 보존

속성 이름 또는 속성 이름/값 쌍에 따라 변환을 건너뛰려면
`html.preserveAttributes`를 사용합니다:

```ts twoslash
import { load } from "@gukhanmun/wasm";
import { stdictFst } from "@gukhanmun/stdict-fst";
// ---cut-before---
const g = await load({
  dictionaries: [await stdictFst()],
  html: {
    preserveAttributes: [
      "data-no-hanja",            // 이 屬性을 가진 任意의 要素
      { name: "lang", value: "en" }, // lang="en"인 要素
    ],
  },
});
```

## HTML에서의 루비(ruby) 마크업

`"text/html"` 형식을 루비 렌더링 모드와 결합합니다:

```ts twoslash
import { load } from "@gukhanmun/wasm";
import { stdictFst } from "@gukhanmun/stdict-fst";
// ---cut-before---
const g = await load({
  rendering: "ruby-on-hangul",
  dictionaries: [await stdictFst()],
});

console.log(g.convert("<p>漢字</p>", "text/html"));
// → <p><ruby>한자<rp>(</rp><rt>漢字</rt><rp>)</rp></ruby></p>
```

`<rp>`(ruby parenthesis) 요소는 폴백을 제공합니다: `<ruby>`를 지원하지 않는
브라우저는 독음을 기저 텍스트에 섞지 않고 괄호 안에(`한자(漢字)`) 표시합니다.
