Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,24 @@

## Phase 15: Refactoring

- [ ] Review `miku-xlsx2md` module boundaries before cutting files
- [ ] Split DOCX package loading and relationship/content-type resolution out of `core.ts` where useful
- [ ] Split document XML block parsing, inline run parsing, table parsing, and drawing/image extraction out of `document-parser.ts`
- [ ] Extract Markdown rendering/escaping helpers into focused modules instead of keeping rendering logic inside parser orchestration
- [ ] Extract asset manifest construction and browser ZIP packaging into focused modules
- [ ] Keep CLI and browser behavior unchanged while refactoring by adding or preserving focused regression tests
- [ ] Update `scripts/lib/docx2md-module-order.mjs` and generated `src/js/` order whenever TypeScript modules are split
- [ ] Re-run `npm run build` and `npm run test:unit` after each refactoring slice
- [x] Review `miku-xlsx2md` module boundaries before cutting files
- [x] Split DOCX package loading and relationship/content-type resolution out of `core.ts` where useful
- [x] Split document XML block parsing, inline run parsing, table parsing, and drawing/image extraction out of `document-parser.ts`
- [x] Extract bookmark anchor normalization and duplicate-claiming helpers into a focused module
- [x] Extract drawing/image unsupported trace description into a focused module
- [x] Extract table grid-span and vertical-merge row construction into a focused module
- [x] Extract Markdown rendering/escaping helpers into focused modules instead of keeping rendering logic inside parser orchestration
- [x] Extract asset manifest construction and browser ZIP packaging into focused modules
- [x] Keep CLI and browser behavior unchanged while refactoring by adding or preserving focused regression tests
- [x] Update `scripts/lib/docx2md-module-order.mjs` and generated `src/js/` order whenever TypeScript modules are split
- [x] Re-run `npm run build` and `npm run test:unit` after each refactoring slice

## Phase 16: Refactoring Resume Notes

- [x] Next safe slice: extract inline run parsing and hyperlink rendering from `document-parser.ts` into `document-inline-parser.ts`
- [x] Keep textbox text extraction close to inline parsing at first because it calls the same run/text/style logic
- [x] Keep `renderStructuredParagraphText` in `document-parser.ts` until inline/textbox extraction is stable
- [x] After inline/textbox extraction, consider splitting top-level block parsing from `parseDocumentXml`
- [x] Split table cell text extraction after inline/textbox callback boundary stabilized
- [x] After each slice, update `scripts/lib/docx2md-module-order.mjs`, `miku-docx2md-src.html`, and generated `src/js/`
- [x] After each slice, run `npm run build`, `npm run test:unit`, `npx tsc --noEmit`, and `git diff --check`
13 changes: 8 additions & 5 deletions docs/docx2md-impl-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ The current first cut includes:
- nested lists based on `numbering.xml`
- structural table extraction
- merge placeholders `←M←` and `↑M↑`
- resolved embedded image asset discovery and optional sidecar export
- lightweight image placeholders or Markdown image links when image metadata permits
- asset manifest output for CLI and browser image asset exports
- summary counts
- unsupported-element diagnostics
- Node.js CLI
- browser UI based on `lht-cmn/`

The current first cut still excludes:

- image extraction
- drawing / shape extraction
- inline image layout reproduction
- drawing / shape layout extraction
- exact layout reproduction
- header / footer, footnotes, comments, tracked changes

Expand All @@ -47,11 +50,11 @@ The current end-to-end flow is:
1. read a `.docx` file as bytes
2. expand ZIP entries in-house
3. load `word/document.xml`
4. optionally load `word/_rels/document.xml.rels`, `word/styles.xml`, and `word/numbering.xml`
4. optionally load `word/_rels/document.xml.rels`, `word/styles.xml`, `word/numbering.xml`, and `[Content_Types].xml`
5. parse document blocks in document order
6. build a lightweight parsed document with `blocks` and `summary`
6. build a lightweight parsed document with `blocks`, `summary`, and any resolved sidecar `assets`
7. render Markdown
8. optionally emit summary text and unsupported debug comments
8. optionally emit summary text, unsupported debug comments, and exported image assets

## 4. ZIP Handling

Expand Down
15 changes: 9 additions & 6 deletions docs/docx2md-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,29 @@ The first cut should focus on textual and structural content that maps cleanly i
- bullet lists
- numbered lists
- tables
- resolved embedded image references as lightweight placeholders or explicit sidecar assets

### 2.4 Out of Scope in First Cut

The first cut intentionally excludes visual and layout-heavy features.
The first cut intentionally excludes visual and layout-heavy reproduction.

- images
- shapes
- SmartArt
- WordArt
- text boxes
- floating objects
- charts
- drawing objects
- inline image layout and sizing fidelity
- exact page layout reproduction
- headers / footers
- footnotes / endnotes
- comments
- tracked changes
- macros

These may be considered later, but should not complicate the first implementation.
Resolved embedded image files may be exposed as sidecar assets, but this does not imply Word-like layout reproduction.
Other visual features may be considered later, but should not complicate the first implementation.

## 3. Target Documents

Expand Down Expand Up @@ -165,7 +167,8 @@ The primary output should be:

- one combined Markdown file

Since images and shapes are out of scope in the first cut, ZIP export is not required initially.
When resolved embedded images are exported explicitly, a sidecar asset directory or archive may accompany the Markdown output.
The primary output remains the Markdown document; sidecar image export is optional and should not require layout reconstruction.

### 5.3 Naming

Expand Down Expand Up @@ -504,7 +507,7 @@ When multiple XML spellings represent the same broad unsupported feature, the im

An implementation may also choose a narrower compromise for text boxes: preserve plain textual paragraphs from `txbxContent` when they can be extracted safely, while still treating textbox layout and placement as unsupported.
For image-like drawing content, an implementation may keep the image unsupported while still emitting a debug-oriented placeholder trace that includes the resolved relationship target and, when safely available, metadata such as alt text (`descr` / `title`) and drawing extent.
When meaningful alt text is available, the implementation may also emit a small non-debug placeholder such as `[Image: ...]` without attempting actual image extraction or layout reproduction.
When meaningful alt text is available, the implementation may also emit a small non-debug placeholder such as `[Image: ...]` without attempting inline layout reproduction.
For Node-oriented workflows, an implementation may additionally expose resolved embedded image package entries as sidecar assets without attempting layout reconstruction or automatic Markdown image embedding.
When such sidecar asset export is enabled explicitly, the implementation may choose to replace that placeholder with a relative Markdown image link such as `![alt](assets/word/media/example.png)`.
When package content types are available, an implementation may prefer those declarations over file-extension inference when reporting exported asset media types.
Expand Down Expand Up @@ -569,7 +572,7 @@ The intended direction is to follow the sibling app style where practical.
- TypeScript as source of truth
- testable core logic

CLI support may be added later, but it does not need to block the first cut.
Current implementations may include CLI support when it follows the same local-processing and testable-core direction.

## 12. Initial Development Priorities

Expand Down
3 changes: 2 additions & 1 deletion docs/upstream.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ When reviewing architecture, documentation style, file layout, build scripts, or

## Scope Note

For `miku-docx2md` first cut, images and shapes are out of scope even though the upstream sibling app handles richer asset extraction in the spreadsheet domain.
For `miku-docx2md`, Word-like visual layout reproduction remains out of scope.
Resolved embedded images may be exposed as sidecar assets, but shapes, charts, floating-object layout, and richer drawing reconstruction should still be treated as document-specific work rather than copied directly from the spreadsheet upstream.
2 changes: 1 addition & 1 deletion index-src.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
<main class="card">
<div class="eyebrow">Local Browser Tool</div>
<h1>miku-docx2md</h1>
<p class="meta">Version 0.8.0 / Updated 2026-04-24</p>
<p class="meta">Version 0.8.1 / Updated 2026-04-24</p>

<section class="lang-block" aria-label="概要">
<h2>What is this?</h2>
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
<main class="card">
<div class="eyebrow">Local Browser Tool</div>
<h1>miku-docx2md</h1>
<p class="meta">Version 0.8.0 / Updated 2026-04-24</p>
<p class="meta">Version 0.8.1 / Updated 2026-04-24</p>

<section class="lang-block" aria-label="概要">
<h2>What is this?</h2>
Expand Down
15 changes: 15 additions & 0 deletions miku-docx2md-src.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,23 @@ <h2 class="md-section-title">Markdown</h2>
<script src="src/js/rels-parser.js"></script>
<script src="src/js/styles-parser.js"></script>
<script src="src/js/numbering-parser.js"></script>
<script src="src/js/document-summary.js"></script>
<script src="src/js/document-anchor-parser.js"></script>
<script src="src/js/document-drawing-parser.js"></script>
<script src="src/js/document-paragraph-parser.js"></script>
<script src="src/js/document-inline-parser.js"></script>
<script src="src/js/document-cell-parser.js"></script>
<script src="src/js/document-table-parser.js"></script>
<script src="src/js/document-block-parser.js"></script>
<script src="src/js/document-parser.js"></script>
<script src="src/js/image-trace.js"></script>
<script src="src/js/docx-assets.js"></script>
<script src="src/js/markdown-renderer.js"></script>
<script src="src/js/summary.js"></script>
<script src="src/js/asset-manifest.js"></script>
<script src="src/js/docx-package-loader.js"></script>
<script src="src/js/core.js"></script>
<script src="src/js/browser-zip.js"></script>
<script src="src/js/main.js"></script>
</body>
</html>
Loading
Loading