.docx(@awacloud/ooxml'sdocx.read()result) →oconv-ir/v1, tier 2.
Module oconvDocxToIr (oconvDocxToIr) | Source packages/front/office/oconv/src/read/docx-to-ir.js | Deps oconvIr, docx | Worker-safe yes
Pure transformation over an already-parsed docx.read(bytes) structure — no bytes, no I/O of its own. Composes only docx's public API, never an @awacloud/ooxml internal.
Resolve
import { ModuleRuntime } from '@awacloud/fw/core/runtime.js';
import { fw_require, modules } from '@awacloud/oconv';
const runtime = new ModuleRuntime();
runtime.registerAll(fw_require);
runtime.registerAll(modules);
const docx = runtime.resolve('docx');
const { docxToIr } = runtime.resolve('oconvDocxToIr');
API
| Member | Signature | Returns | Throws |
|---|---|---|---|
docxToIr |
(readResult: object, opts?: object) => {ir, losses} |
ir — an oconv-ir/v1 document; losses — {code, detail}[] in document order |
— |
Examples
Convert a .docx read result to IR
const { ir, losses } = docxToIr(docx.read(bytes));
ir.kind; // 'document'
losses; // [] for a plain document with no tracked features
Notes
-
Headings are resolved from
pPr.pStylein three steps:- a style ID matching
Heading1..Heading6(case-insensitive) gives that level; - otherwise the style's built-in
w:nameis looked up in the document'sstyles.xml(readResult.styles). Built-in names stay language-invariant when Word localizes the ID — a FrenchTitre1is still namedheading 1— soheading 1..heading 6give that level; - the built-in name
Titlebecomes a level-1 heading;Subtitlebecomes a plain paragraph and recordsheading/subtitle-degraded(detail = the style ID, one loss per subtitle paragraph, even an empty one).
A style ID that matches no rule and whose name resolves to nothing stays a paragraph with no loss — the reader cannot know it was meant as a heading. Limit: a document without a
styles.xmlpart has no names to resolve, so only step 1 applies and a localizedTitre1reads as a plain paragraph.basedOnchains, numbered heading styles, character styles andw:aliasesare not consulted. A resolved heading style takes precedence overpPr.numPr. - a style ID matching
-
Monospace runs (
run.code) are detected by a frozen, name-based allowlist ofrPr.fontvalues (consolas,courier new, …,src/read/docx-to-ir.js'sMONO_FONTS); a font outside the list yields a plain run with no per-node loss. -
Lists: consecutive paragraphs sharing one
pPr.numPr.numIdgroup into one IRlist; an item atilvl > 0is flattened into the enclosing single-level list (losslist/nesting-flattened, recorded once per document, not once per item); anumIdthat does not resolve to a concrete<w:num>falls back tolist{ordered:false}(losslist/numbering-unresolved). -
Tables: no row is ever marked
header—docx.read()surfaces no first-class header-row signal. -
Loss codes this module emits:
heading/subtitle-degraded(a paragraph styledSubtitlekept as a plain paragraph, detail = its style ID),link/target-missing(an unresolved hyperlinkrId, text kept),list/numbering-unresolved,list/nesting-flattened,image/bytes-unavailable(a drawing's image bytes did not resolve on read),block/dropped(an unmapped body/cell node, detail = itstype). -
Page layout, sections, headers/footers, footnotes, comments, tracked changes and font colours are permanently out of scope and never reported per node — see the loss matrix for the full docx→md row.
See also
- docs/api/README.md — full module index +
exportsboundary note oconvIr— the pivot this reader producesoconv— the facade composing this reader intotoMd/convert- loss matrix