[{"data":1,"prerenderedAt":559},["ShallowReactive",2],{"lit-docx-doc:\u002Fen\u002Fguide\u002Freading":3},{"id":4,"title":5,"body":6,"description":547,"extension":548,"keywords":549,"locale":551,"meta":552,"navigation":553,"order":23,"path":554,"section":555,"seo":556,"stem":557,"__hash__":558},"docs\u002Fguide\u002Freading.en.md","Reading DOCX",{"type":7,"value":8,"toc":539},"minimark",[9,52,57,63,124,133,137,142,191,194,199,202,246,250,373,377,387,425,535],[10,11,16],"pre",{"className":12,"code":13,"language":14,"meta":15,"style":15},"language-ts shiki shiki-themes github-light github-light github-dark","parseDocx(buffer: Uint8Array, options?: ParseOptions): Promise\u003CParseResult>\n","ts","",[17,18,19],"code",{"__ignoreMap":15},[20,21,24,28,32,36,39,43,46,49],"span",{"class":22,"line":23},"line",1,[20,25,27],{"class":26},"sgQzM","parseDocx",[20,29,31],{"class":30},"sVPnS","(buffer: Uint8Array, options",[20,33,35],{"class":34},"sDD9d","?:",[20,37,38],{"class":30}," ParseOptions): ",[20,40,42],{"class":41},"sUNQB","Promise",[20,44,45],{"class":34},"\u003C",[20,47,48],{"class":30},"ParseResult",[20,50,51],{"class":34},">\n",[53,54,56],"h2",{"id":55},"preparing-the-input","Preparing the input",[58,59,60,62],"p",{},[17,61,27],{}," only accepts bytes and never reads files itself, so in every environment the caller obtains the bytes:",[64,65,66,79],"table",{},[67,68,69],"thead",{},[70,71,72,76],"tr",{},[73,74,75],"th",{},"Source",[73,77,78],{},"Code",[80,81,82,93,110],"tbody",{},[70,83,84,88],{},[85,86,87],"td",{},"A file in Node",[85,89,90],{},[17,91,92],{},"new Uint8Array(await readFile(path))",[70,94,95,105],{},[85,96,97,98,101,102],{},"A browser ",[17,99,100],{},"\u003Cinput type=\"file\">"," or dropped ",[17,103,104],{},"File",[85,106,107],{},[17,108,109],{},"new Uint8Array(await file.arrayBuffer())",[70,111,112,119],{},[85,113,114,115,118],{},"A ",[17,116,117],{},"fetch"," response",[85,120,121],{},[17,122,123],{},"new Uint8Array(await response.arrayBuffer())",[58,125,126,129,130,132],{},[17,127,128],{},"Blob"," and ",[17,131,104],{}," cannot be passed directly; convert them to bytes first.",[53,134,136],{"id":135},"the-result","The result",[58,138,139,141],{},[17,140,48],{}," has exactly two fields:",[143,144,145,170],"ul",{},[146,147,148,151,152,155,156,159,160,163,164,169],"li",{},[17,149,150],{},"ast",": the root of the document tree, with ",[17,153,154],{},"type"," ",[17,157,158],{},"\"document\"",". Body blocks are its ",[17,161,162],{},"children","; see ",[165,166,168],"a",{"href":167},"\u002Fen\u002Fguide\u002Flitast","The LitAST node model"," for their shape.",[146,171,172,175,176,178,179,182,183,186,187,190],{},[17,173,174],{},"warnings",": non-fatal problems. Each has a stable ",[17,177,17],{},", a readable ",[17,180,181],{},"message",", and optionally a ",[17,184,185],{},"location"," (where in the XML) and an ",[17,188,189],{},"element"," (the tag name).",[58,192,193],{},"Parsing avoids stopping: when one piece of content cannot be recognized or fails to process, it becomes a warning and the rest of the document is still read.",[195,196,198],"h3",{"id":197},"where-the-data-lives","Where the data lives",[58,200,201],{},"Styles, numbering and images are not returned as separate fields:",[143,203,204,219,236],{},[146,205,206,210,211,214,215,218],{},[207,208,209],"strong",{},"Images"," are embedded in ",[17,212,213],{},"image"," nodes as a data URL in ",[17,216,217],{},"attrs.src",". Image types and file signatures are checked before the URL is created.",[146,220,221,224,225,129,228,231,232,235],{},[207,222,223],{},"Styles and numbering"," are used during parsing to compute the formatting of paragraphs, text and lists, and the results appear on those nodes. The original ",[17,226,227],{},"styles.xml",[17,229,230],{},"numbering.xml"," are kept in ",[17,233,234],{},"ast.meta.rawXmlFiles"," and written back on generation.",[146,237,238,241,242,245],{},[207,239,240],{},"Comments, footnotes, endnotes, document properties and settings"," are package-level data under ",[17,243,244],{},"ast.meta",".",[53,247,249],{"id":248},"parse-options","Parse options",[64,251,252,265],{},[67,253,254],{},[70,255,256,259,262],{},[73,257,258],{},"Option",[73,260,261],{},"Default",[73,263,264],{},"Effect",[80,266,267,296,324,347,360],{},[70,268,269,274,277],{},[85,270,271],{},[17,272,273],{},"preserveRawXml",[85,275,276],{},"keep",[85,278,279,280,283,284,287,288,291,292,295],{},"Unrecognized elements become ",[17,281,282],{},"unknownBlock"," \u002F ",[17,285,286],{},"unknownInline"," nodes with their original XML in ",[17,289,290],{},"rawXml",", written back unchanged on generation. Only an explicit ",[17,293,294],{},"false"," drops them",[70,297,298,303,308],{},[85,299,300],{},[17,301,302],{},"numberingMode",[85,304,305],{},[17,306,307],{},"\"nested-lists\"",[85,309,310,312,313,283,316,319,320,323],{},[17,311,307],{}," rebuilds numbered paragraphs as nested ",[17,314,315],{},"list",[17,317,318],{},"listItem"," nodes; ",[17,321,322],{},"\"flat-numbered-paragraphs\""," keeps Word's flat numbered paragraphs",[70,325,326,331,336],{},[85,327,328],{},[17,329,330],{},"malformedFieldMode",[85,332,333],{},[17,334,335],{},"\"best-effort\"",[85,337,338,339,342,343,346],{},"For malformed complex fields, ",[17,340,341],{},"best-effort"," keeps the content with a warning, ",[17,344,345],{},"strict"," rejects the current text story",[70,348,349,354,357],{},[85,350,351],{},[17,352,353],{},"plugins",[85,355,356],{},"none",[85,358,359],{},"Extra parser plugins, consulted after the built-in ones",[70,361,362,367,370],{},[85,363,364],{},[17,365,366],{},"chartSourceLimits",[85,368,369],{},"built-in limits",[85,371,372],{},"Bounds the size of chart source data; exceeding them rejects the import",[53,374,376],{"id":375},"errors","Errors",[58,378,379,380,383,384,386],{},"These cases throw ",[17,381,382],{},"DocxPackageError"," before any content is read; tell them apart by ",[17,385,17],{},":",[64,388,389,400],{},[67,390,391],{},[70,392,393,397],{},[73,394,395],{},[17,396,17],{},[73,398,399],{},"Meaning",[80,401,402,412],{},[70,403,404,409],{},[85,405,406],{},[17,407,408],{},"invalid-zip-container",[85,410,411],{},"The bytes are not a ZIP package, for example the wrong file was passed",[70,413,414,419],{},[85,415,416],{},[17,417,418],{},"unsupported-compound-file-container",[85,420,421,422],{},"An OLE compound file, typically an encrypted DOCX or a legacy ",[17,423,424],{},".doc",[10,426,428],{"className":12,"code":427,"language":14,"meta":15,"style":15},"try {\n  const { ast } = await parseDocx(bytes);\n} catch (error) {\n  if (error instanceof DocxPackageError && error.code === \"unsupported-compound-file-container\") {\n    \u002F\u002F Tell the user the file is encrypted or a legacy .doc\n  } else throw error;\n}\n",[17,429,430,438,464,476,507,514,529],{"__ignoreMap":15},[20,431,432,435],{"class":22,"line":23},[20,433,434],{"class":34},"try",[20,436,437],{"class":30}," {\n",[20,439,441,444,447,449,452,455,458,461],{"class":22,"line":440},2,[20,442,443],{"class":34},"  const",[20,445,446],{"class":30}," { ",[20,448,150],{"class":41},[20,450,451],{"class":30}," } ",[20,453,454],{"class":34},"=",[20,456,457],{"class":34}," await",[20,459,460],{"class":26}," parseDocx",[20,462,463],{"class":30},"(bytes);\n",[20,465,467,470,473],{"class":22,"line":466},3,[20,468,469],{"class":30},"} ",[20,471,472],{"class":34},"catch",[20,474,475],{"class":30}," (error) {\n",[20,477,479,482,485,488,491,494,497,500,504],{"class":22,"line":478},4,[20,480,481],{"class":34},"  if",[20,483,484],{"class":30}," (error ",[20,486,487],{"class":34},"instanceof",[20,489,490],{"class":26}," DocxPackageError",[20,492,493],{"class":34}," &&",[20,495,496],{"class":30}," error.code ",[20,498,499],{"class":34},"===",[20,501,503],{"class":502},"s-HEn"," \"unsupported-compound-file-container\"",[20,505,506],{"class":30},") {\n",[20,508,510],{"class":22,"line":509},5,[20,511,513],{"class":512},"sqmzS","    \u002F\u002F Tell the user the file is encrypted or a legacy .doc\n",[20,515,517,520,523,526],{"class":22,"line":516},6,[20,518,519],{"class":30},"  } ",[20,521,522],{"class":34},"else",[20,524,525],{"class":34}," throw",[20,527,528],{"class":30}," error;\n",[20,530,532],{"class":22,"line":531},7,[20,533,534],{"class":30},"}\n",[536,537,538],"style",{},"html pre.shiki code .sgQzM, html code.shiki .sgQzM{--shiki-default:#6F42C1;--shiki-light:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVPnS, html code.shiki .sVPnS{--shiki-default:#24292E;--shiki-light:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sDD9d, html code.shiki .sDD9d{--shiki-default:#D73A49;--shiki-light:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sUNQB, html code.shiki .sUNQB{--shiki-default:#005CC5;--shiki-light:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s-HEn, html code.shiki .s-HEn{--shiki-default:#032F62;--shiki-light:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sqmzS, html code.shiki .sqmzS{--shiki-default:#6A737D;--shiki-light:#6A737D;--shiki-dark:#6A737D}",{"title":15,"searchDepth":440,"depth":440,"links":540},[541,542,545,546],{"id":55,"depth":440,"text":56},{"id":135,"depth":440,"text":136,"children":543},[544],{"id":197,"depth":466,"text":198},{"id":248,"depth":440,"text":249},{"id":375,"depth":440,"text":376},"Inputs, options, results, warnings and errors of parseDocx, and where styles, numbering and images end up in the result.","md",[27,550,174,382],"ParseOptions","en",{},true,"\u002Fen\u002Fguide\u002Freading","Guides",{"title":5,"description":547},"guide\u002Freading.en","GjQCgh3bjpS3jV3gQpS-mx01XBZIJrRMu5ukuq6kD0w",1793045343967]