render_hwp_html
Convert a single page of an HWP/HWPX file to HTML. Useful for AI processing when SVG output is not suitable.
Instructions
Render a single page of an HWP/HWPX as HTML. Useful for AI consumption when SVG isn't ideal. Args: file_path, page (0-based, default 0), output_path (optional).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| page | No | ||
| output_path | No |
Implementation Reference
- src/tools/render-extra.ts:15-38 (handler)The main handler function `renderHwpHtml` that executes the tool logic: opens an HWP/HWPX document, renders a specified page as HTML string, optionally saves to output_path. Uses `doc.renderPageHtml(page)` to generate HTML.
export async function renderHwpHtml(args: RenderHtmlArgs): Promise<string> { let doc; try { doc = await openDocument(args.file_path); } catch (e) { return (e as Error).message; } try { const pages = getPageCount(doc); if (pages === 0) return "(렌더할 페이지가 없습니다 / no pages)"; const page = args.page ?? 0; if (page < 0 || page >= pages) { return `페이지 범위 오류 (page out of range): ${page} (총 ${pages}페이지, 0-based)`; } const html = doc.renderPageHtml(page); if (!args.output_path) return html; writeFileSync(args.output_path, html); return `HTML 저장 완료 (saved): ${args.output_path}\n페이지: ${page + 1}/${pages} | 크기: ${html.length} bytes`; } catch (e) { return `HTML 렌더 오류 (HTML render error): ${(e as Error).message}`; } finally { closeDocument(doc); } } - src/tools/render-extra.ts:9-13 (schema)TypeScript interface `RenderHtmlArgs` defining the input schema: file_path (required), page (optional, default 0), output_path (optional).
export interface RenderHtmlArgs { file_path: string; page?: number; output_path?: string; } - src/server.ts:466-479 (registration)Tool registration in the TOOLS array with name 'render_hwp_html', description, and inputSchema (JSON Schema format with file_path, page, output_path).
{ name: "render_hwp_html", description: "Render a single page of an HWP/HWPX as HTML. Useful for AI consumption when SVG isn't ideal. Args: file_path, page (0-based, default 0), output_path (optional).", inputSchema: { type: "object", properties: { file_path: { type: "string" }, page: { type: "number" }, output_path: { type: "string" }, }, required: ["file_path"], }, }, - src/server.ts:542-543 (registration)Handler mapping in the HANDLERS record: `render_hwp_html: renderHwpHtml` which maps the tool name to the handler function.
render_hwp_html: renderHwpHtml, render_hwp_equation_svg: renderHwpEquationSvg, - src/tools/render-extra.ts:1-7 (helper)Imports used by the handler: writeFileSync from fs, and closeDocument/getPageCount/openDocument from '../core/document.js', and initRhwp from '../core/wasm-init.js'.
import { writeFileSync } from "node:fs"; import { closeDocument, getPageCount, openDocument, } from "../core/document.js"; import { initRhwp } from "../core/wasm-init.js";