delete_hwp_paragraph
Delete a specific paragraph from an HWPX document by providing its zero-based index. Optionally save to a new file path.
Instructions
Delete the Nth paragraph (0-based) from an .hwpx body. Args: file_path, index, output_path (optional).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| index | Yes | ||
| output_path | No |
Implementation Reference
- src/server.ts:231-244 (registration)Registration of the 'delete_hwp_paragraph' tool in the MCP server tool list with its name, description, and input schema.
{ name: "delete_hwp_paragraph", description: "Delete the Nth paragraph (0-based) from an .hwpx body. Args: file_path, index, output_path (optional).", inputSchema: { type: "object", properties: { file_path: { type: "string" }, index: { type: "number" }, output_path: { type: "string" }, }, required: ["file_path", "index"], }, }, - src/server.ts:527-527 (registration)Binding the tool name 'delete_hwp_paragraph' to the handler function deleteHwpParagraph in the tool dispatch map.
delete_hwp_paragraph: deleteHwpParagraph, - src/server.ts:20-20 (registration)Import of deleteHwpParagraph handler from src/tools/edit.ts.
deleteHwpParagraph, - src/tools/edit.ts:65-69 (schema)The DeleteParaArgs interface defining the input schema (file_path, index, output_path) for delete_hwp_paragraph.
export interface DeleteParaArgs { file_path: string; index: number; output_path?: string; } - src/tools/edit.ts:71-84 (handler)The deleteHwpParagraph handler function that validates input, preflights the file, and delegates to deleteHwpxParagraph in core.
export async function deleteHwpParagraph(args: DeleteParaArgs): Promise<string> { const err = preflight(args.file_path); if (err) return err; const out = args.output_path && args.output_path.length > 0 ? args.output_path : defaultOutput(args.file_path, "deleted"); try { const r = await deleteHwpxParagraph(args.file_path, out, args.index); if (r.deleted === 0) return `인덱스 범위 초과 (index out of range): ${args.index} (총 ${r.total})`; return `문단 ${args.index} 삭제 (deleted): 1건 / 전체 ${r.total}\n저장 (saved): ${out}`; } catch (e) { return `문단 삭제 오류 (delete error): ${(e as Error).message}`; } } - src/core/hwpx-mutate.ts:214-228 (helper)The deleteHwpxParagraph core helper that loads the .hwpx zip, finds the paragraph by index using PARA_REGEX, removes its XML, and writes the modified file.
export async function deleteHwpxParagraph( inputPath: string, outputPath: string, index: number ): Promise<{ deleted: number; total: number }> { const { zip, sectionName, xml } = await loadSection(inputPath); const matches = [...xml.matchAll(PARA_REGEX)]; if (index < 0 || index >= matches.length) { return { deleted: 0, total: matches.length }; } const target = matches[index][0]; const newXml = xml.replace(target, ""); await writeSection(zip, sectionName, newXml, outputPath); return { deleted: 1, total: matches.length }; } - src/core/hwpx-mutate.ts:159-159 (helper)The PARA_REGEX constant used to match <hp:p> paragraphs in the XML.
const PARA_REGEX = /<hp:p [^>]*>[\s\S]*?<\/hp:p>/g;