hwp2md 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["data: Uint8Array | ArrayBuffer","streams: string[][]","records: Record[]","cells: Cell[]","row: number","col: number","colspan: number","rowspan: number","textParts: string[]","cellText: string","cell: Cell","matrix: string[][]","lines: string[]","result: string[]","reader: RecordReader","options: ConvertOptions","tables: string[]","paragraphs: Paragraph[]","lines: string[]","allParagraphs: Paragraph[]"],"sources":["../../src/utils/compression.ts","../../src/parser.ts","../../src/record.ts","../../src/table.ts","../../src/paragraph.ts","../../src/converter.ts","../../src/cli/index.ts"],"sourcesContent":["import { inflateRaw } from \"pako\";\n\n/**\n * Decompress raw deflate data (no zlib header)\n * Equivalent to Python: zlib.decompress(data, -15)\n *\n * HWP files use raw deflate compression without zlib wrapper headers.\n * The windowBits=-15 in Python indicates raw deflate mode.\n *\n * @param data - Compressed data\n * @returns Decompressed data\n */\nexport function decompressRaw(data: Uint8Array): Uint8Array {\n try {\n return inflateRaw(data);\n } catch (error) {\n throw new Error(`Failed to decompress data: ${(error as Error).message}`);\n }\n}\n\n/**\n * Check if data appears to be compressed\n * This is a heuristic check, not foolproof\n */\nexport function looksCompressed(data: Uint8Array): boolean {\n if (data.length < 2) return false;\n\n // Check for common compression headers\n // zlib: 0x78 0x9C, 0x78 0x01, 0x78 0xDA, etc.\n if (data[0] === 0x78) return true;\n\n // Raw deflate doesn't have a header, so this is just a guess\n // Check for low entropy (lots of zeros or repeated patterns)\n let zeros = 0;\n for (let i = 0; i < Math.min(100, data.length); i++) {\n if (data[i] === 0) zeros++;\n }\n\n // If less than 10% zeros in first 100 bytes, might be compressed\n return zeros < 10;\n}\n","/**\n * HWP 5.0 File Parser\n * Parses OLE Compound File format HWP files\n */\n\nimport * as CFB from \"cfb\";\nimport { decompressRaw } from \"./utils/compression\";\nimport type { FileHeader } from \"./types\";\n\n/**\n * HWP File Parser\n * Reads and parses HWP 5.0 files using OLE Compound File format\n */\nexport class HWPFile {\n private cfb: CFB.CFB$Container | null = null;\n private _fileHeader: FileHeader | null = null;\n private _isCompressed: boolean = false;\n\n /**\n * Create HWPFile from raw data\n * @param data - Raw HWP file data\n */\n constructor(private data: Uint8Array | ArrayBuffer) {}\n\n /**\n * Create HWPFile from file path (Node.js only)\n * @param path - Path to HWP file\n */\n static async fromFile(path: string): Promise<HWPFile> {\n const fs = await import(\"node:fs/promises\");\n const data = await fs.readFile(path);\n return new HWPFile(new Uint8Array(data));\n }\n\n /**\n * Create HWPFile from ArrayBuffer\n * @param data - ArrayBuffer data\n */\n static fromArrayBuffer(data: ArrayBuffer): HWPFile {\n return new HWPFile(new Uint8Array(data));\n }\n\n /**\n * Create HWPFile from Uint8Array\n * @param data - Uint8Array data\n */\n static fromUint8Array(data: Uint8Array): HWPFile {\n return new HWPFile(data);\n }\n\n /**\n * Open and parse HWP file\n */\n open(): void {\n const uint8Array =\n this.data instanceof Uint8Array ? this.data : new Uint8Array(this.data);\n\n // Check for HWP 3.0 format (HWP 97, 2002, etc.)\n // HWP 3.0 files start with \"HWP Document File V3.00\"\n if (uint8Array.length >= 30) {\n const signature = new TextDecoder(\"utf-8\")\n .decode(uint8Array.slice(0, 30))\n .replace(/\\0+$/, \"\");\n\n if (signature.startsWith(\"HWP Document File V3\")) {\n throw new Error(\n \"HWP 3.0 format (HWP 97, 2002, etc.) is not supported. \" +\n \"Please use HWP 5.0 or later format. \" +\n \"You can convert HWP 3.0 files to HWP 5.0 format using Hancom Office.\",\n );\n }\n }\n\n try {\n // cfb library works best with Buffer in Node.js\n // Check if Buffer is available (Node.js environment)\n if (typeof Buffer !== \"undefined\") {\n const buffer = Buffer.from(uint8Array);\n this.cfb = CFB.read(buffer, { type: \"buffer\" });\n } else {\n // Browser environment - convert to regular array\n const buffer = Array.from(uint8Array);\n this.cfb = CFB.read(buffer, { type: \"array\" });\n }\n } catch (error) {\n throw new Error(`Failed to parse HWP file: ${(error as Error).message}`);\n }\n\n this._fileHeader = this.parseFileHeader();\n this._isCompressed = this._fileHeader.isCompressed;\n }\n\n /**\n * Close HWP file and release resources\n */\n close(): void {\n this.cfb = null;\n this._fileHeader = null;\n }\n\n /**\n * Get file header information\n */\n get fileHeader(): FileHeader | null {\n return this._fileHeader;\n }\n\n /**\n * Check if file is compressed\n */\n get isCompressed(): boolean {\n return this._isCompressed;\n }\n\n /**\n * Parse FileHeader stream (256 bytes fixed)\n */\n private parseFileHeader(): FileHeader {\n if (!this.cfb) {\n throw new Error(\"HWP file not opened\");\n }\n\n const entry = CFB.find(this.cfb, \"FileHeader\");\n if (!entry) {\n throw new Error(\"FileHeader not found in HWP file\");\n }\n\n const data = entry.content as Uint8Array;\n if (data.length !== 256) {\n throw new Error(`Invalid FileHeader size: ${data.length} (expected 256)`);\n }\n\n // Signature (32 bytes)\n const signatureBytes = data.slice(0, 32);\n const signature = new TextDecoder(\"utf-8\")\n .decode(signatureBytes)\n .replace(/\\0+$/, \"\");\n\n if (!signature.startsWith(\"HWP Document File\")) {\n throw new Error(`Invalid HWP signature: ${signature}`);\n }\n\n // Version (4 bytes at offset 32, little-endian)\n const view = new DataView(data.buffer, data.byteOffset, data.byteLength);\n const versionRaw = view.getUint32(32, true);\n const major = (versionRaw >> 24) & 0xff;\n const minor = (versionRaw >> 16) & 0xff;\n const patch = (versionRaw >> 8) & 0xff;\n const rev = versionRaw & 0xff;\n\n // Properties (4 bytes at offset 36)\n const properties = view.getUint32(36, true);\n const isCompressed = Boolean(properties & 0x01);\n const isEncrypted = Boolean(properties & 0x02);\n\n return {\n signature,\n version: `${major}.${minor}.${patch}.${rev}`,\n isCompressed,\n isEncrypted,\n rawProperties: properties,\n };\n }\n\n /**\n * Read and decompress stream\n * @param streamPath - Stream path (e.g., 'DocInfo', 'BodyText/Section0')\n * @returns Decompressed data or null if stream doesn't exist\n */\n readStream(streamPath: string): Uint8Array | null {\n if (!this.cfb) {\n return null;\n }\n\n const entry = CFB.find(this.cfb, streamPath);\n if (!entry) {\n return null;\n }\n\n let data = entry.content as Uint8Array;\n\n // Decompress if needed\n if (this._isCompressed) {\n try {\n data = decompressRaw(data);\n } catch (error) {\n throw new Error(\n `Failed to decompress ${streamPath}: ${(error as Error).message}`,\n );\n }\n }\n\n return data;\n }\n\n /**\n * List all streams in HWP file\n * @returns Array of stream paths\n */\n listStreams(): string[][] {\n if (!this.cfb) {\n return [];\n }\n\n const streams: string[][] = [];\n for (const entry of this.cfb.FileIndex) {\n if (entry.type === 2) {\n // Stream type\n const path = entry.name.split(\"/\").filter((p) => p);\n if (path.length > 0) {\n streams.push(path);\n }\n }\n }\n return streams;\n }\n\n /**\n * Get file information\n */\n getFileInfo(): Record<string, unknown> {\n if (!this._fileHeader) {\n return {};\n }\n\n return {\n signature: this._fileHeader.signature,\n version: this._fileHeader.version,\n compressed: this._isCompressed,\n encrypted: this._fileHeader.isEncrypted,\n streams: this.listStreams(),\n };\n }\n\n /**\n * Get number of sections in BodyText\n */\n getSectionCount(): number {\n if (!this.cfb) {\n return 0;\n }\n\n let count = 0;\n // Try both BodyText/SectionN and SectionN paths\n while (\n CFB.find(this.cfb, `BodyText/Section${count}`) ||\n CFB.find(this.cfb, `Section${count}`)\n ) {\n count++;\n }\n\n return count;\n }\n\n /**\n * Read section data\n * @param sectionIndex - Section index (0-based)\n * @returns Decompressed section data\n */\n readSection(sectionIndex: number): Uint8Array | null {\n // Try BodyText/SectionN first, then SectionN\n let data = this.readStream(`BodyText/Section${sectionIndex}`);\n if (!data) {\n data = this.readStream(`Section${sectionIndex}`);\n }\n return data;\n }\n}\n","/**\n * HWP Record Reader\n * Parses HWP's record-based binary format\n */\n\nimport type { Record } from \"./types\";\n\n// Tag IDs (Document Info)\nexport const HWPTAG_BEGIN = 0x010;\nexport const HWPTAG_DOCUMENT_PROPERTIES = 0x010;\nexport const HWPTAG_ID_MAPPINGS = 0x011;\nexport const HWPTAG_BIN_DATA = 0x012;\nexport const HWPTAG_FACE_NAME = 0x013;\nexport const HWPTAG_BORDER_FILL = 0x014;\nexport const HWPTAG_CHAR_SHAPE = 0x015;\nexport const HWPTAG_TAB_DEF = 0x016;\nexport const HWPTAG_NUMBERING = 0x017;\nexport const HWPTAG_BULLET = 0x018;\nexport const HWPTAG_PARA_SHAPE = 0x019;\nexport const HWPTAG_STYLE = 0x01a;\n\n// Body text tags (HWPTAG_BEGIN + decimal offset)\nexport const HWPTAG_PARA_HEADER = HWPTAG_BEGIN + 50; // 0x042\nexport const HWPTAG_PARA_TEXT = HWPTAG_BEGIN + 51; // 0x043\nexport const HWPTAG_PARA_CHAR_SHAPE = HWPTAG_BEGIN + 52; // 0x044\nexport const HWPTAG_PARA_LINE_SEG = HWPTAG_BEGIN + 53; // 0x045\nexport const HWPTAG_PARA_RANGE_TAG = HWPTAG_BEGIN + 54; // 0x046\nexport const HWPTAG_CTRL_HEADER = HWPTAG_BEGIN + 55; // 0x047\nexport const HWPTAG_LIST_HEADER = HWPTAG_BEGIN + 56; // 0x048\nexport const HWPTAG_PAGE_DEF = HWPTAG_BEGIN + 57; // 0x049\nexport const HWPTAG_FOOTNOTE_SHAPE = HWPTAG_BEGIN + 58; // 0x04a\nexport const HWPTAG_PAGE_BORDER_FILL = HWPTAG_BEGIN + 59; // 0x04b\nexport const HWPTAG_SHAPE_COMPONENT = HWPTAG_BEGIN + 60; // 0x04c\nexport const HWPTAG_TABLE = HWPTAG_BEGIN + 61; // 0x04d\nexport const HWPTAG_SHAPE_COMPONENT_LINE = HWPTAG_BEGIN + 62; // 0x04e\nexport const HWPTAG_CTRL_DATA = HWPTAG_BEGIN + 71; // 0x057\n\n/**\n * HWP Record Reader\n * Reads binary records from HWP stream data\n */\nexport class RecordReader {\n private data: Uint8Array;\n private offset: number = 0;\n\n constructor(data: Uint8Array) {\n this.data = data;\n }\n\n /**\n * Check if there are more records to read\n */\n hasMore(): boolean {\n return this.offset < this.data.length;\n }\n\n /**\n * Read next record\n * @returns Next record, or null if no more records\n */\n readRecord(): Record | null {\n // Check if we have at least 4 bytes for the record header\n if (this.offset + 4 > this.data.length) {\n return null;\n }\n\n // Parse record header (4 bytes)\n const view = new DataView(\n this.data.buffer,\n this.data.byteOffset + this.offset,\n 4,\n );\n const header = view.getUint32(0, true);\n\n const tagId = header & 0x3ff; // Lower 10 bits\n const level = (header >> 10) & 0x3ff; // Middle 10 bits\n let size = (header >> 20) & 0xfff; // Upper 12 bits\n\n // Move past header\n let dataOffset = this.offset + 4;\n\n // Extended size if size == 0xFFF\n if (size === 0xfff) {\n // Check if we have 4 bytes for extended size\n if (dataOffset + 4 > this.data.length) {\n return null;\n }\n const extView = new DataView(\n this.data.buffer,\n this.data.byteOffset + dataOffset,\n 4,\n );\n size = extView.getUint32(0, true);\n dataOffset += 4;\n }\n\n // Check if we have enough data for the record body\n if (dataOffset + size > this.data.length) {\n return null;\n }\n\n // Extract record data\n const recordData = this.data.slice(dataOffset, dataOffset + size);\n\n // Move offset to next record\n this.offset = dataOffset + size;\n\n return { tagId, level, data: recordData, size };\n }\n\n /**\n * Peek at next record header without consuming it\n * @returns Header info with tagId, level, size\n */\n peekRecordHeader(): { tagId: number; level: number; size: number } | null {\n // Check if we have at least 4 bytes for the record header\n if (this.offset + 4 > this.data.length) {\n return null;\n }\n\n // Parse header\n const view = new DataView(\n this.data.buffer,\n this.data.byteOffset + this.offset,\n 4,\n );\n const header = view.getUint32(0, true);\n\n const tagId = header & 0x3ff;\n const level = (header >> 10) & 0x3ff;\n let size = (header >> 20) & 0xfff;\n\n let dataOffset = this.offset + 4;\n\n if (size === 0xfff) {\n // Check if we have 4 bytes for extended size\n if (dataOffset + 4 > this.data.length) {\n return null;\n }\n const extView = new DataView(\n this.data.buffer,\n this.data.byteOffset + dataOffset,\n 4,\n );\n size = extView.getUint32(0, true);\n }\n\n return { tagId, level, size };\n }\n\n /**\n * Read all records (considering hierarchy)\n * @param parentLevel - Stop when reaching this level or below\n * @returns All records at current level\n */\n readAllRecords(parentLevel?: number): Record[] {\n const records: Record[] = [];\n\n while (this.hasMore()) {\n // Peek at next record\n const header = this.peekRecordHeader();\n if (!header) {\n break;\n }\n\n // Check if we should stop (returned to parent level)\n if (parentLevel !== undefined && header.level <= parentLevel) {\n break;\n }\n\n // Read record\n const record = this.readRecord();\n if (record) {\n records.push(record);\n }\n }\n\n return records;\n }\n\n /**\n * Get current position\n */\n get position(): number {\n return this.offset;\n }\n\n /**\n * Get remaining bytes\n */\n get remaining(): number {\n return this.data.length - this.offset;\n }\n}\n","/**\n * HWP Table Parser\n * Parses table records and converts to Markdown\n */\n\nimport {\n RecordReader,\n HWPTAG_LIST_HEADER,\n HWPTAG_PARA_HEADER,\n HWPTAG_PARA_TEXT,\n} from \"./record\";\nimport { parseParaText, processControlChars } from \"./paragraph\";\nimport type { Table, Cell, MergeStrategy } from \"./types\";\n\n/**\n * Parse table properties from TABLE record data\n * @param data - TABLE record data\n * @returns Table properties with rows, cols\n */\nexport function parseTableProperties(data: Uint8Array): {\n properties: number;\n rows: number;\n cols: number;\n} {\n if (data.length < 8) {\n throw new Error(`Invalid TABLE record size: ${data.length}`);\n }\n\n const view = new DataView(data.buffer, data.byteOffset, data.byteLength);\n\n // Properties flag (4 bytes)\n const properties = view.getUint32(0, true);\n\n // Row count (2 bytes)\n const rows = view.getUint16(4, true);\n\n // Column count (2 bytes)\n const cols = view.getUint16(6, true);\n\n return { properties, rows, cols };\n}\n\n/**\n * Parse cell properties\n * @param data - Cell property data\n * @returns Cell properties\n */\nexport function parseCellProperties(data: Uint8Array): {\n col: number;\n row: number;\n colspan: number;\n rowspan: number;\n} {\n if (data.length < 8) {\n return {\n col: 0,\n row: 0,\n colspan: 1,\n rowspan: 1,\n };\n }\n\n const view = new DataView(data.buffer, data.byteOffset, data.byteLength);\n\n // Column address (2 bytes)\n const col = view.getUint16(0, true);\n\n // Row address (2 bytes)\n const row = view.getUint16(2, true);\n\n // Column span (2 bytes)\n const colspan = view.getUint16(4, true);\n\n // Row span (2 bytes)\n const rowspan = view.getUint16(6, true);\n\n return { col, row, colspan, rowspan };\n}\n\n/**\n * Parse table from TABLE record and subsequent records\n * @param tableRecordData - TABLE record data\n * @param reader - Record reader for reading cell data\n * @param lineBreakStyle - How to handle line breaks in cells\n * @returns Parsed table\n */\nexport function parseTable(\n tableRecordData: Uint8Array,\n reader: RecordReader,\n lineBreakStyle: \"space\" | \"br\" = \"space\",\n): Table {\n // Parse table properties\n const props = parseTableProperties(tableRecordData);\n const rows = props.rows;\n const cols = props.cols;\n\n const cells: Cell[] = [];\n let cellIndex = 0;\n\n // Read cells from LIST_HEADER records\n while (reader.hasMore() && cellIndex < rows * cols) {\n const header = reader.peekRecordHeader();\n if (!header) {\n break;\n }\n\n // Stop if we're back to level 0 or 1 (end of table)\n if (header.level < 2) {\n break;\n }\n\n // Read LIST_HEADER (cell start)\n if (header.tagId === HWPTAG_LIST_HEADER) {\n const listRecord = reader.readRecord();\n if (!listRecord) {\n break;\n }\n\n // Parse cell properties from LIST_HEADER (offset 8)\n let row: number, col: number, colspan: number, rowspan: number;\n\n if (listRecord.data.length >= 16) {\n const view = new DataView(\n listRecord.data.buffer,\n listRecord.data.byteOffset,\n listRecord.data.byteLength,\n );\n col = view.getUint16(8, true);\n row = view.getUint16(10, true);\n colspan = view.getUint16(12, true);\n rowspan = view.getUint16(14, true);\n\n // Fix colspan/rowspan (0 means 1)\n if (colspan === 0) colspan = 1;\n if (rowspan === 0) rowspan = 1;\n } else {\n // Fallback: use index\n row = Math.floor(cellIndex / cols);\n col = cellIndex % cols;\n colspan = 1;\n rowspan = 1;\n }\n\n // Read cell text from paragraphs\n const textParts: string[] = [];\n\n while (reader.hasMore()) {\n const paraHeader = reader.peekRecordHeader();\n if (!paraHeader) {\n break;\n }\n\n // Stop at next cell or end of table\n if (paraHeader.tagId === HWPTAG_LIST_HEADER) {\n break;\n }\n if (paraHeader.level < 2) {\n break;\n }\n\n // Read paragraph\n if (paraHeader.tagId === HWPTAG_PARA_HEADER) {\n const paraRec = reader.readRecord();\n if (!paraRec) {\n break;\n }\n\n // Parse paragraph header\n if (paraRec.data.length >= 4) {\n const view = new DataView(\n paraRec.data.buffer,\n paraRec.data.byteOffset,\n paraRec.data.byteLength,\n );\n const nchars = view.getUint32(0, true) & 0x7fffffff;\n\n // Read text if present\n if (nchars > 0 && reader.hasMore()) {\n const nextH = reader.peekRecordHeader();\n if (nextH && nextH.tagId === HWPTAG_PARA_TEXT) {\n const textRec = reader.readRecord();\n if (textRec) {\n // Use parseParaText to handle control chars properly\n const rawText = parseParaText(textRec.data, nchars);\n const processed = processControlChars(rawText);\n const text = processed.text;\n\n if (text.trim()) {\n textParts.push(text.trim());\n }\n }\n }\n }\n }\n } else {\n // Skip other records in cell\n reader.readRecord();\n }\n }\n\n // Create cell: handle line breaks based on style\n let cellText: string;\n if (lineBreakStyle === \"br\") {\n // Human-readable: use <br> for visual line breaks\n cellText = textParts.join(\"<br>\");\n cellText = cellText.replace(/\\n/g, \"<br>\");\n } else {\n // LLM-optimized (default): use space for clean text\n cellText = textParts.join(\" \");\n cellText = cellText.replace(/\\n/g, \" \");\n }\n\n const cell: Cell = { row, col, rowspan, colspan, text: cellText };\n cells.push(cell);\n cellIndex++;\n } else {\n // Skip non-LIST_HEADER records\n reader.readRecord();\n }\n }\n\n return { rows, cols, cells };\n}\n\n/**\n * Convert table to Markdown\n * @param table - Table object\n * @param mergeStrategy - 'repeat' (default) or 'blank'\n * @returns Markdown table\n */\nexport function tableToMarkdown(\n table: Table,\n mergeStrategy: MergeStrategy = \"repeat\",\n): string {\n const { rows, cols, cells } = table;\n\n // Create matrix\n const matrix: string[][] = Array.from({ length: rows }, () =>\n Array(cols).fill(\"\"),\n );\n\n // Fill matrix with cell data\n for (const cell of cells) {\n if (mergeStrategy === \"repeat\") {\n // Repeat content in all merged cells\n for (let r = cell.row; r < cell.row + cell.rowspan; r++) {\n for (let c = cell.col; c < cell.col + cell.colspan; c++) {\n if (r < rows && c < cols) {\n matrix[r][c] = cell.text;\n }\n }\n }\n } else {\n // Only fill first cell\n if (cell.row < rows && cell.col < cols) {\n matrix[cell.row][cell.col] = cell.text;\n }\n }\n }\n\n // Generate Markdown table\n const lines: string[] = [];\n\n if (rows === 0 || cols === 0) {\n return \"[Empty Table]\";\n }\n\n // Empty header row (Korean docs often use tables for layout, not data)\n lines.push(\"| \" + Array(cols).fill(\"\").join(\" | \") + \" |\");\n lines.push(\"| \" + Array(cols).fill(\"---\").join(\" | \") + \" |\");\n\n // All rows as body (including original first row)\n for (const row of matrix) {\n lines.push(\"| \" + row.join(\" | \") + \" |\");\n }\n\n return lines.join(\"\\n\");\n}\n","/**\n * HWP Paragraph Parser\n * Parses paragraph records and extracts text\n */\n\nimport {\n RecordReader,\n HWPTAG_PARA_HEADER,\n HWPTAG_PARA_TEXT,\n HWPTAG_CTRL_HEADER,\n HWPTAG_TABLE,\n} from \"./record\";\nimport type { Paragraph, ParagraphHeader, ConvertOptions } from \"./types\";\nimport { parseTable, tableToMarkdown } from \"./table\";\n\n/**\n * Parse paragraph header\n * @param data - PARA_HEADER record data\n * @returns Paragraph header information\n */\nexport function parseParaHeader(data: Uint8Array): ParagraphHeader {\n if (data.length < 22) {\n throw new Error(`Invalid PARA_HEADER size: ${data.length}`);\n }\n\n const view = new DataView(data.buffer, data.byteOffset, data.byteLength);\n\n // Number of characters (nchars)\n const ncharsRaw = view.getUint32(0, true);\n const textCount = ncharsRaw & 0x7fffffff; // Remove sign bit if present\n\n // Control mask\n const controlMask = view.getUint32(4, true);\n\n // Para shape ID\n const paraShapeId = view.getUint16(8, true);\n\n // Style ID\n const styleId = view.getUint8(10);\n\n // Column type\n const columnType = view.getUint8(11);\n\n // Char shape count\n const charShapeCount = view.getUint16(12, true);\n\n return {\n textCount,\n controlMask,\n paraShapeId,\n styleId,\n columnType,\n charShapeCount,\n };\n}\n\n/**\n * Parse paragraph text with control info table\n *\n * PARA_TEXT structure:\n * [Control info table: 16 bytes per control] + [Actual text]\n *\n * Each control info block (16 bytes):\n * - 2 bytes: control code\n * - 4 bytes: control ID\n * - 8 bytes: control data\n * - 2 bytes: control code (repeated)\n *\n * @param data - PARA_TEXT record data\n * @param nchars - Number of WCHAR characters (control table + text)\n * @returns Decoded text\n */\nexport function parseParaText(data: Uint8Array, _nchars: number): string {\n // Control character types WITHOUT additional data in control table\n const CHAR_CONTROLS = new Set([0x00, 0x0a, 0x0d, 0x1e, 0x1f]);\n\n let offset = 0;\n\n // Phase 1: Skip control info table\n // Control info blocks always start with control code (< 32)\n // Actual text starts with regular character (>= 32)\n while (offset + 2 <= data.length) {\n const view = new DataView(data.buffer, data.byteOffset + offset, 2);\n const charCode = view.getUint16(0, true);\n\n if (charCode < 32 && !CHAR_CONTROLS.has(charCode)) {\n // This is a control info block (16 bytes)\n offset += 16;\n if (offset > data.length) {\n break;\n }\n } else {\n // Found start of actual text\n break;\n }\n }\n\n // Phase 2: Parse actual text\n const textData = data.slice(offset);\n\n if (textData.length === 0) {\n return \"\";\n }\n\n // Decode UTF-16LE (handles surrogate pairs correctly)\n try {\n const decoder = new TextDecoder(\"utf-16le\");\n return decoder.decode(textData);\n } catch (error) {\n // Fallback: return empty string\n return \"\";\n }\n}\n\n/**\n * Process control characters in text\n * @param text - Raw text with control characters\n * @returns Processed text and has_table flag\n */\nexport function processControlChars(text: string): {\n text: string;\n hasTable: boolean;\n} {\n const result: string[] = [];\n let hasTable = false;\n\n for (const char of text) {\n const code = char.codePointAt(0) ?? 0;\n\n if (code < 32) {\n // Control character\n if (code === 10) {\n // 0x0A: line break\n result.push(\"\\n\");\n } else if (code === 11) {\n // 0x0B: table/object marker\n // Tables are handled by CTRL_HEADER records, not text markers\n // Just skip this control character\n hasTable = true;\n } else if (code === 13) {\n // 0x0D: para break\n result.push(\"\\n\");\n }\n // Ignore other control chars\n } else {\n result.push(char);\n }\n }\n\n return { text: result.join(\"\"), hasTable };\n}\n\n/**\n * Paragraph Parser\n * Parses paragraphs from HWP record stream\n */\nexport class ParagraphParser {\n constructor(\n private reader: RecordReader,\n private options: ConvertOptions = {},\n ) {\n // Default table line break style\n if (!this.options.tableLineBreakStyle) {\n this.options.tableLineBreakStyle = \"space\";\n }\n }\n\n /**\n * Parse next paragraph\n * @returns Parsed paragraph, or null if no more paragraphs\n */\n parseParagraph(): Paragraph | null {\n if (!this.reader.hasMore()) {\n return null;\n }\n\n // Find PARA_HEADER\n let record = null;\n while (this.reader.hasMore()) {\n record = this.reader.readRecord();\n if (record && record.tagId === HWPTAG_PARA_HEADER) {\n break;\n }\n record = null;\n }\n\n if (!record) {\n return null;\n }\n\n const header = parseParaHeader(record.data);\n\n // Read PARA_TEXT if present\n let text = \"\";\n\n if (header.textCount > 0) {\n // Peek to see if next is PARA_TEXT\n const nextHeader = this.reader.peekRecordHeader();\n if (nextHeader && nextHeader.tagId === HWPTAG_PARA_TEXT) {\n record = this.reader.readRecord();\n if (record) {\n const rawText = parseParaText(record.data, header.textCount);\n const processed = processControlChars(rawText);\n text = processed.text;\n // hasTable flag from processed.hasTable is not used currently\n }\n }\n }\n\n // Process control records (tables, etc.)\n const tables: string[] = [];\n while (this.reader.hasMore()) {\n const nextHeader = this.reader.peekRecordHeader();\n if (!nextHeader) {\n break;\n }\n\n // Stop if we hit next paragraph or lower level\n if (nextHeader.tagId === HWPTAG_PARA_HEADER) {\n break;\n }\n if (nextHeader.level === 0) {\n break;\n }\n\n // Check for table (CTRL_HEADER followed by TABLE)\n if (nextHeader.tagId === HWPTAG_CTRL_HEADER) {\n this.reader.readRecord(); // Skip CTRL_HEADER\n\n // Check for TABLE\n const tableHeader = this.reader.peekRecordHeader();\n if (tableHeader && tableHeader.tagId === HWPTAG_TABLE) {\n const tableRecord = this.reader.readRecord();\n if (tableRecord) {\n try {\n const table = parseTable(\n tableRecord.data,\n this.reader,\n this.options.tableLineBreakStyle,\n );\n const tableMd = tableToMarkdown(table);\n tables.push(tableMd);\n } catch (error) {\n console.warn(\"Warning: Failed to parse table:\", error);\n tables.push(\"[TABLE - Parse Error]\");\n }\n }\n } else {\n // Other control types, skip for now\n }\n } else {\n // Skip other records (char shapes, line segments, etc.)\n this.reader.readRecord();\n }\n }\n\n // Append tables after paragraph text\n if (tables.length > 0) {\n // Add tables as separate blocks after the text\n text = text.trimEnd();\n\n // Check if text is just garbled control characters (short, all non-ASCII)\n // If so, skip the text and just use the table\n const isGarbled =\n text.length > 0 &&\n text.length < 5 &&\n [...text].every((c) => {\n const code = c.codePointAt(0) ?? 0;\n return code > 127 || /\\s/.test(c);\n });\n\n if (isGarbled) {\n // Skip garbled text, just use tables\n text = tables.join(\"\\n\\n\");\n } else {\n // Include both text and tables\n if (text) {\n text += \"\\n\\n\";\n }\n text += tables.join(\"\\n\\n\");\n }\n }\n\n return { text, header };\n }\n\n /**\n * Parse all paragraphs in section\n * @returns All paragraphs\n */\n parseAllParagraphs(): Paragraph[] {\n const paragraphs: Paragraph[] = [];\n\n while (this.reader.hasMore()) {\n const para = this.parseParagraph();\n if (para) {\n paragraphs.push(para);\n } else {\n break;\n }\n }\n\n return paragraphs;\n }\n}\n","/**\n * HWP/HWPX to Markdown Converter\n * Orchestrates conversion from HWP/HWPX to Markdown\n */\n\nimport { HWPFile } from \"./parser\";\nimport { RecordReader } from \"./record\";\nimport { ParagraphParser } from \"./paragraph\";\nimport {\n HWPXFile,\n parseHwpxSection,\n isHwpxData,\n isHwpxPath,\n} from \"./hwpx_parser\";\nimport type { Paragraph, ConvertOptions } from \"./types\";\n\n/**\n * Convert paragraphs to Markdown\n * @param paragraphs - List of paragraphs\n * @returns Markdown text\n */\nexport function paragraphsToMarkdown(paragraphs: Paragraph[]): string {\n const lines: string[] = [];\n\n for (const para of paragraphs) {\n const text = para.text.trim();\n if (!text) {\n continue;\n }\n\n // Skip paragraphs that are likely garbled control characters\n // These appear as short mysterious character sequences before tables\n if (\n text.length < 5 &&\n !text.startsWith(\"|\") &&\n [...text].every((c) => (c.codePointAt(0) ?? 0) > 127)\n ) {\n continue;\n }\n\n lines.push(text);\n }\n\n return lines.join(\"\\n\\n\");\n}\n\n/**\n * Convert HWP file to Markdown\n * @param hwp - Opened HWP file\n * @param options - Conversion options\n * @returns Markdown content\n */\nexport function convertHwpToMarkdown(\n hwp: HWPFile,\n options: ConvertOptions = {},\n): string {\n const allParagraphs: Paragraph[] = [];\n\n // Default options\n if (!options.tableLineBreakStyle) {\n options.tableLineBreakStyle = \"space\";\n }\n\n // Process each section\n const sectionCount = hwp.getSectionCount();\n\n for (let i = 0; i < sectionCount; i++) {\n // Read section data\n const sectionData = hwp.readSection(i);\n if (!sectionData) {\n continue;\n }\n\n // Parse records\n const reader = new RecordReader(sectionData);\n const parser = new ParagraphParser(reader, options);\n\n // Parse paragraphs\n const paragraphs = parser.parseAllParagraphs();\n allParagraphs.push(...paragraphs);\n }\n\n // Convert to Markdown\n const markdown = paragraphsToMarkdown(allParagraphs);\n\n return markdown;\n}\n\n/**\n * Convert HWPX file to Markdown\n * @param hwpx - Opened HWPX file\n * @param options - Conversion options\n * @returns Markdown content\n */\nexport function convertHwpxToMarkdown(\n hwpx: HWPXFile,\n options: ConvertOptions = {},\n): string {\n const allParagraphs: Paragraph[] = [];\n\n const sectionCount = hwpx.getSectionCount();\n for (let i = 0; i < sectionCount; i++) {\n const sectionObj = hwpx.getSectionXml(i) as Record<string, unknown>;\n const paragraphs = parseHwpxSection(sectionObj, options);\n allParagraphs.push(...paragraphs);\n }\n\n return paragraphsToMarkdown(allParagraphs);\n}\n\n/**\n * High-level API: Convert HWP/HWPX file to Markdown\n * Auto-detects format based on file extension or magic bytes.\n * @param input - File path (Node.js), ArrayBuffer, or Uint8Array\n * @param options - Conversion options\n * @returns Markdown content\n */\nexport async function convert(\n input: string | ArrayBuffer | Uint8Array,\n options?: ConvertOptions,\n): Promise<string> {\n // Detect HWPX format\n if (typeof input === \"string\" && isHwpxPath(input)) {\n const hwpx = await HWPXFile.fromFile(input);\n try {\n hwpx.open();\n return convertHwpxToMarkdown(hwpx, options);\n } finally {\n hwpx.close();\n }\n }\n\n if (\n (input instanceof Uint8Array || input instanceof ArrayBuffer) &&\n isHwpxData(input instanceof ArrayBuffer ? new Uint8Array(input) : input)\n ) {\n const hwpx =\n input instanceof Uint8Array\n ? HWPXFile.fromUint8Array(input)\n : HWPXFile.fromArrayBuffer(input);\n try {\n hwpx.open();\n return convertHwpxToMarkdown(hwpx, options);\n } finally {\n hwpx.close();\n }\n }\n\n // Default: HWP format\n let hwp: HWPFile;\n if (typeof input === \"string\") {\n hwp = await HWPFile.fromFile(input);\n } else if (input instanceof Uint8Array) {\n hwp = HWPFile.fromUint8Array(input);\n } else {\n hwp = HWPFile.fromArrayBuffer(input);\n }\n\n try {\n hwp.open();\n return convertHwpToMarkdown(hwp, options);\n } finally {\n hwp.close();\n }\n}\n","#!/usr/bin/env node\n/**\n * HWP2MD CLI\n * Command-line interface for HWP to Markdown conversion\n */\n\nimport { Command } from \"commander\";\nimport { readFile, writeFile } from \"node:fs/promises\";\nimport { convertHwpToMarkdown } from \"../converter\";\nimport { HWPFile } from \"../parser\";\n\nconst program = new Command();\n\nprogram\n .name(\"hwp2md\")\n .description(\"HWP to Markdown converter\")\n .version(\"0.1.0\");\n\nprogram\n .command(\"info <file>\")\n .description(\"Display HWP file information\")\n .action(async (file: string) => {\n try {\n const data = await readFile(file);\n const hwp = new HWPFile(new Uint8Array(data));\n hwp.open();\n\n const header = hwp.fileHeader;\n\n console.log(`File: ${file}`);\n console.log(`Signature: ${header?.signature}`);\n console.log(`Version: ${header?.version}`);\n console.log(`Compressed: ${hwp.isCompressed}`);\n console.log(`Encrypted: ${header?.isEncrypted}`);\n console.log(`Sections: ${hwp.getSectionCount()}`);\n\n hwp.close();\n } catch (error) {\n console.error(`Error: ${(error as Error).message}`);\n process.exit(1);\n }\n });\n\nprogram\n .command(\"convert <input> [output]\")\n .description(\"Convert HWP file to Markdown\")\n .option(\n \"--table-line-breaks <style>\",\n \"Line break style in table cells: space or br\",\n \"space\",\n )\n .action(\n async (\n input: string,\n output: string | undefined,\n options: { tableLineBreaks: string },\n ) => {\n const outputPath = output ?? input.replace(/\\.hwp$/i, \".md\");\n\n try {\n console.log(`Converting ${input} to ${outputPath}...`);\n\n const data = await readFile(input);\n const hwp = new HWPFile(new Uint8Array(data));\n hwp.open();\n\n const markdown = convertHwpToMarkdown(hwp, {\n tableLineBreakStyle: options.tableLineBreaks as \"space\" | \"br\",\n });\n\n await writeFile(outputPath, markdown, \"utf-8\");\n console.log(`Conversion completed: ${outputPath}`);\n\n hwp.close();\n } catch (error) {\n console.error(`Error: ${(error as Error).message}`);\n process.exit(1);\n }\n },\n );\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAYA,SAAgB,cAAc,MAA8B;AAC1D,KAAI;AACF,SAAO,WAAW,KAAK;UAChB,OAAO;AACd,QAAM,IAAI,MAAM,8BAA+B,MAAgB,UAAU;;;;;;;;;;;;;;ACH7E,IAAa,UAAb,MAAa,QAAQ;CACnB,AAAQ,MAAgC;CACxC,AAAQ,cAAiC;CACzC,AAAQ,gBAAyB;;;;;CAMjC,YAAY,AAAQA,MAAgC;EAAhC;;;;;;CAMpB,aAAa,SAAS,MAAgC;EAEpD,MAAM,OAAO,OADF,MAAM,OAAO,qBACF,SAAS,KAAK;AACpC,SAAO,IAAI,QAAQ,IAAI,WAAW,KAAK,CAAC;;;;;;CAO1C,OAAO,gBAAgB,MAA4B;AACjD,SAAO,IAAI,QAAQ,IAAI,WAAW,KAAK,CAAC;;;;;;CAO1C,OAAO,eAAe,MAA2B;AAC/C,SAAO,IAAI,QAAQ,KAAK;;;;;CAM1B,OAAa;EACX,MAAM,aACJ,KAAK,gBAAgB,aAAa,KAAK,OAAO,IAAI,WAAW,KAAK,KAAK;AAIzE,MAAI,WAAW,UAAU,IAKvB;OAJkB,IAAI,YAAY,QAAQ,CACvC,OAAO,WAAW,MAAM,GAAG,GAAG,CAAC,CAC/B,QAAQ,QAAQ,GAAG,CAER,WAAW,uBAAuB,CAC9C,OAAM,IAAI,MACR,iKAGD;;AA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