Skip to content

Commit 4a34907

Browse files
fix(xl-docx-exporter): improve OOXML interoperability (#2206)
* Move Inter font settings into Normal style and normalize rFonts (ascii/cs/eastAsia/hAnsi) * Use ECMA-376 shading semantics (w:val="clear" + w:fill) instead of w:color + "solid" * Emit table cell widths as numeric dxa values (twips) instead of "pt" strings * Introduce SourceCode, VerbatimChar, and BlockQuote styles and map code/quotes to them This makes the generated DOCX closer to Word’s own output and improves behavior in Word, LibreOffice, and converters like Pandoc and DocSpec.
1 parent 9e5ffa8 commit 4a34907

File tree

15 files changed

+298
-118
lines changed

15 files changed

+298
-118
lines changed

packages/xl-docx-exporter/src/docx/__snapshots__/basic/document.xml

Lines changed: 32 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
<w:document mc:Ignorable="w14 w15 wp14" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml" xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex">
33
<w:body>
44
<w:p>
5-
<w:pPr>
6-
<w:pStyle w:val="Normal"/>
7-
<w:rPr>
8-
<w:rFonts w:ascii="Inter" w:cs="Inter" w:eastAsia="Inter" w:hAnsi="Inter"/>
9-
</w:rPr>
10-
</w:pPr>
115
<w:r>
126
<w:rPr>
137
<w:i/>
@@ -26,12 +20,6 @@
2620
</w:r>
2721
</w:p>
2822
<w:p>
29-
<w:pPr>
30-
<w:pStyle w:val="Normal"/>
31-
<w:rPr>
32-
<w:rFonts w:ascii="Inter" w:cs="Inter" w:eastAsia="Inter" w:hAnsi="Inter"/>
33-
</w:rPr>
34-
</w:pPr>
3523
<w:r>
3624
<w:tab/>
3725
</w:r>
@@ -40,12 +28,6 @@
4028
</w:r>
4129
</w:p>
4230
<w:p>
43-
<w:pPr>
44-
<w:pStyle w:val="Normal"/>
45-
<w:rPr>
46-
<w:rFonts w:ascii="Inter" w:cs="Inter" w:eastAsia="Inter" w:hAnsi="Inter"/>
47-
</w:rPr>
48-
</w:pPr>
4931
<w:r>
5032
<w:tab/>
5133
</w:r>
@@ -58,11 +40,7 @@
5840
</w:p>
5941
<w:p>
6042
<w:pPr>
61-
<w:pStyle w:val="Normal"/>
62-
<w:shd w:color="fbe4e4" w:val="solid"/>
63-
<w:rPr>
64-
<w:rFonts w:ascii="Inter" w:cs="Inter" w:eastAsia="Inter" w:hAnsi="Inter"/>
65-
</w:rPr>
43+
<w:shd w:fill="fbe4e4" w:val="clear"/>
6644
</w:pPr>
6745
<w:r>
6846
<w:rPr>
@@ -73,12 +51,6 @@
7351
</w:r>
7452
</w:p>
7553
<w:p>
76-
<w:pPr>
77-
<w:pStyle w:val="Normal"/>
78-
<w:rPr>
79-
<w:rFonts w:ascii="Inter" w:cs="Inter" w:eastAsia="Inter" w:hAnsi="Inter"/>
80-
</w:rPr>
81-
</w:pPr>
8254
<w:r>
8355
<w:t xml:space="preserve">Paragraph</w:t>
8456
</w:r>
@@ -102,11 +74,7 @@
10274
</w:p>
10375
<w:p>
10476
<w:pPr>
105-
<w:pStyle w:val="Normal"/>
10677
<w:jc w:val="distribute"/>
107-
<w:rPr>
108-
<w:rFonts w:ascii="Inter" w:cs="Inter" w:eastAsia="Inter" w:hAnsi="Inter"/>
109-
</w:rPr>
11078
</w:pPr>
11179
<w:r>
11280
<w:t xml:space="preserve">justified paragraph. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</w:t>
@@ -209,7 +177,7 @@
209177
<w:ilvl w:val="2"/>
210178
<w:numId w:val="3"/>
211179
</w:numPr>
212-
<w:shd w:color="fbe4e4" w:val="solid"/>
180+
<w:shd w:fill="fbe4e4" w:val="clear"/>
213181
<w:jc w:val="right"/>
214182
<w:rPr>
215183
<w:color w:val="0b6e99"/>
@@ -226,7 +194,7 @@
226194
<w:ilvl w:val="2"/>
227195
<w:numId w:val="3"/>
228196
</w:numPr>
229-
<w:shd w:color="fbe4e4" w:val="solid"/>
197+
<w:shd w:fill="fbe4e4" w:val="clear"/>
230198
<w:jc w:val="center"/>
231199
<w:rPr>
232200
<w:color w:val="0b6e99"/>
@@ -291,7 +259,7 @@
291259
<w:tr>
292260
<w:tc>
293261
<w:tcPr>
294-
<w:tcW w:type="dxa" w:w="150pt"/>
262+
<w:tcW w:type="dxa" w:w="3000"/>
295263
<w:gridSpan w:val="1"/>
296264
</w:tcPr>
297265
<w:p>
@@ -324,7 +292,7 @@
324292
<w:tr>
325293
<w:tc>
326294
<w:tcPr>
327-
<w:tcW w:type="dxa" w:w="150pt"/>
295+
<w:tcW w:type="dxa" w:w="3000"/>
328296
<w:gridSpan w:val="1"/>
329297
</w:tcPr>
330298
<w:p>
@@ -357,7 +325,7 @@
357325
<w:tr>
358326
<w:tc>
359327
<w:tcPr>
360-
<w:tcW w:type="dxa" w:w="150pt"/>
328+
<w:tcW w:type="dxa" w:w="3000"/>
361329
<w:gridSpan w:val="1"/>
362330
</w:tcPr>
363331
<w:p>
@@ -529,14 +497,7 @@
529497
<w:t xml:space="preserve">From https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3</w:t>
530498
</w:r>
531499
</w:p>
532-
<w:p>
533-
<w:pPr>
534-
<w:pStyle w:val="Normal"/>
535-
<w:rPr>
536-
<w:rFonts w:ascii="Inter" w:cs="Inter" w:eastAsia="Inter" w:hAnsi="Inter"/>
537-
</w:rPr>
538-
</w:pPr>
539-
</w:p>
500+
<w:p/>
540501
<w:p>
541502
<w:hyperlink w:history="1" r:id="FAKE-ID">
542503
<w:r>
@@ -556,12 +517,6 @@
556517
</w:r>
557518
</w:p>
558519
<w:p>
559-
<w:pPr>
560-
<w:pStyle w:val="Normal"/>
561-
<w:rPr>
562-
<w:rFonts w:ascii="Inter" w:cs="Inter" w:eastAsia="Inter" w:hAnsi="Inter"/>
563-
</w:rPr>
564-
</w:pPr>
565520
<w:r>
566521
<w:rPr>
567522
<w:b/>
@@ -571,20 +526,14 @@
571526
</w:r>
572527
</w:p>
573528
<w:p>
574-
<w:pPr>
575-
<w:pStyle w:val="Normal"/>
576-
<w:rPr>
577-
<w:rFonts w:ascii="Inter" w:cs="Inter" w:eastAsia="Inter" w:hAnsi="Inter"/>
578-
</w:rPr>
579-
</w:pPr>
580529
<w:r>
581530
<w:rPr>
582531
<w:b/>
583532
<w:bCs/>
584533
<w:i/>
585534
<w:iCs/>
586535
<w:color w:val="e03e3e"/>
587-
<w:shd w:fill="ddebf1"/>
536+
<w:shd w:fill="ddebf1" w:val="clear"/>
588537
</w:rPr>
589538
<w:t xml:space="preserve">Styled Text</w:t>
590539
</w:r>
@@ -721,8 +670,7 @@
721670
</w:tbl>
722671
<w:p>
723672
<w:pPr>
724-
<w:pStyle w:val="Codeblock"/>
725-
<w:shd w:fill="161616" w:color="161616" w:val="solid"/>
673+
<w:pStyle w:val="SourceCode"/>
726674
</w:pPr>
727675
<w:r>
728676
<w:t xml:space="preserve">const helloWorld = (message) =&gt; {</w:t>
@@ -736,13 +684,36 @@
736684
<w:t xml:space="preserve">};</w:t>
737685
</w:r>
738686
</w:p>
687+
<w:p>
688+
<w:r>
689+
<w:rPr>
690+
<w:b/>
691+
<w:bCs/>
692+
</w:rPr>
693+
<w:t xml:space="preserve">Some inline code: </w:t>
694+
</w:r>
695+
<w:r>
696+
<w:rPr>
697+
<w:rStyle w:val="VerbatimChar"/>
698+
</w:rPr>
699+
<w:t xml:space="preserve">var foo = &apos;bar&apos;;</w:t>
700+
</w:r>
701+
</w:p>
739702
<w:p>
740703
<w:pPr>
741704
<w:pBdr>
742705
<w:top w:val="single" w:color="auto" w:sz="1" w:space="1"/>
743706
</w:pBdr>
744707
</w:pPr>
745708
</w:p>
709+
<w:p>
710+
<w:pPr>
711+
<w:pStyle w:val="BlockQuote"/>
712+
</w:pPr>
713+
<w:r>
714+
<w:t xml:space="preserve">All those moments will be lost in time, like tears in rain.</w:t>
715+
</w:r>
716+
</w:p>
746717
<w:sectPr>
747718
<w:pgSz w:w="11906" w:h="16838" w:orient="portrait"/>
748719
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>

packages/xl-docx-exporter/src/docx/__snapshots__/basic/styles.xml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@
404404
<w:spacing w:before="45" w:after="45" w:line="360" w:lineRule="auto"/>
405405
</w:pPr>
406406
<w:rPr>
407-
<w:rFonts w:ascii="Inter" w:hAnsi="Inter" w:cs="Times New Roman (Body CS)"/>
407+
<w:rFonts w:ascii="Inter" w:cs="Inter" w:eastAsia="Inter" w:hAnsi="Inter"/>
408408
</w:rPr>
409409
</w:style>
410410
<w:style w:type="paragraph" w:styleId="Heading1">
@@ -597,6 +597,13 @@
597597
<w:uiPriority w:val="1"/>
598598
<w:unhideWhenUsed/>
599599
</w:style>
600+
<w:style w:type="character" w:customStyle="1" w:styleId="VerbatimChar">
601+
<w:name w:val="Verbatim Char"/>
602+
<w:basedOn w:val="DefaultParagraphFont"/>
603+
<w:rPr>
604+
<w:rFonts w:ascii="GeistMono" w:cs="GeistMono" w:eastAsia="GeistMono" w:hAnsi="GeistMono"/>
605+
</w:rPr>
606+
</w:style>
600607
<w:style w:type="table" w:default="1" w:styleId="TableNormal">
601608
<w:name w:val="Normal Table"/>
602609
<w:uiPriority w:val="99"/>
@@ -948,13 +955,31 @@
948955
<w:szCs w:val="18"/>
949956
</w:rPr>
950957
</w:style>
951-
<w:style w:type="paragraph" w:styleId="Codeblock">
952-
<w:name w:val="Codeblock"/>
958+
<w:style w:type="paragraph" w:customStyle="1" w:styleId="SourceCode">
959+
<w:name w:val="Source Code"/>
953960
<w:basedOn w:val="Normal"/>
961+
<w:link w:val="VerbatimChar"/>
962+
<w:pPr>
963+
<w:shd w:val="solid" w:color="161616" w:fill="161616"/>
964+
</w:pPr>
954965
<w:rPr>
955966
<w:noProof/>
967+
<w:wordWrap w:val="off"/>
956968
<w:color w:val="ffffff"/>
957969
<w:rFonts w:ascii="GeistMono" w:cs="GeistMono" w:eastAsia="GeistMono" w:hAnsi="GeistMono"/>
958970
</w:rPr>
959971
</w:style>
972+
<w:style w:type="paragraph" w:styleId="BlockQuote">
973+
<w:name w:val="Block Quote"/>
974+
<w:basedOn w:val="Normal"/>
975+
<w:next w:val="Normal"/>
976+
<w:uiPriority w:val="9"/>
977+
<w:unhideWhenUsed/>
978+
<w:qFormat/>
979+
<w:pPr>
980+
<w:pBdr>
981+
<w:left w:val="single" w:color="7D797A" w:sz="8" w:space="100"/>
982+
</w:pBdr>
983+
</w:pPr>
984+
</w:style>
960985
</w:styles>

packages/xl-docx-exporter/src/docx/__snapshots__/withMultiColumn/document.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@
2525
<w:tcW w:type="pct" w:w="26.666666666666668%"/>
2626
</w:tcPr>
2727
<w:p>
28-
<w:pPr>
29-
<w:pStyle w:val="Normal"/>
30-
<w:rPr>
31-
<w:rFonts w:ascii="Inter" w:cs="Inter" w:eastAsia="Inter" w:hAnsi="Inter"/>
32-
</w:rPr>
33-
</w:pPr>
3428
<w:r>
3529
<w:t xml:space="preserve">This paragraph is in a column!</w:t>
3630
</w:r>
@@ -54,12 +48,6 @@
5448
<w:tcW w:type="pct" w:w="26.666666666666668%"/>
5549
</w:tcPr>
5650
<w:p>
57-
<w:pPr>
58-
<w:pStyle w:val="Normal"/>
59-
<w:rPr>
60-
<w:rFonts w:ascii="Inter" w:cs="Inter" w:eastAsia="Inter" w:hAnsi="Inter"/>
61-
</w:rPr>
62-
</w:pPr>
6351
<w:r>
6452
<w:t xml:space="preserve">You can have multiple blocks in a column too</w:t>
6553
</w:r>

packages/xl-docx-exporter/src/docx/__snapshots__/withMultiColumn/styles.xml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@
404404
<w:spacing w:before="45" w:after="45" w:line="360" w:lineRule="auto"/>
405405
</w:pPr>
406406
<w:rPr>
407-
<w:rFonts w:ascii="Inter" w:hAnsi="Inter" w:cs="Times New Roman (Body CS)"/>
407+
<w:rFonts w:ascii="Inter" w:cs="Inter" w:eastAsia="Inter" w:hAnsi="Inter"/>
408408
</w:rPr>
409409
</w:style>
410410
<w:style w:type="paragraph" w:styleId="Heading1">
@@ -597,6 +597,13 @@
597597
<w:uiPriority w:val="1"/>
598598
<w:unhideWhenUsed/>
599599
</w:style>
600+
<w:style w:type="character" w:customStyle="1" w:styleId="VerbatimChar">
601+
<w:name w:val="Verbatim Char"/>
602+
<w:basedOn w:val="DefaultParagraphFont"/>
603+
<w:rPr>
604+
<w:rFonts w:ascii="GeistMono" w:cs="GeistMono" w:eastAsia="GeistMono" w:hAnsi="GeistMono"/>
605+
</w:rPr>
606+
</w:style>
600607
<w:style w:type="table" w:default="1" w:styleId="TableNormal">
601608
<w:name w:val="Normal Table"/>
602609
<w:uiPriority w:val="99"/>
@@ -948,13 +955,31 @@
948955
<w:szCs w:val="18"/>
949956
</w:rPr>
950957
</w:style>
951-
<w:style w:type="paragraph" w:styleId="Codeblock">
952-
<w:name w:val="Codeblock"/>
958+
<w:style w:type="paragraph" w:customStyle="1" w:styleId="SourceCode">
959+
<w:name w:val="Source Code"/>
953960
<w:basedOn w:val="Normal"/>
961+
<w:link w:val="VerbatimChar"/>
962+
<w:pPr>
963+
<w:shd w:val="solid" w:color="161616" w:fill="161616"/>
964+
</w:pPr>
954965
<w:rPr>
955966
<w:noProof/>
967+
<w:wordWrap w:val="off"/>
956968
<w:color w:val="ffffff"/>
957969
<w:rFonts w:ascii="GeistMono" w:cs="GeistMono" w:eastAsia="GeistMono" w:hAnsi="GeistMono"/>
958970
</w:rPr>
959971
</w:style>
972+
<w:style w:type="paragraph" w:styleId="BlockQuote">
973+
<w:name w:val="Block Quote"/>
974+
<w:basedOn w:val="Normal"/>
975+
<w:next w:val="Normal"/>
976+
<w:uiPriority w:val="9"/>
977+
<w:unhideWhenUsed/>
978+
<w:qFormat/>
979+
<w:pPr>
980+
<w:pBdr>
981+
<w:left w:val="single" w:color="7D797A" w:sz="8" w:space="100"/>
982+
</w:pBdr>
983+
</w:pPr>
984+
</w:style>
960985
</w:styles>

0 commit comments

Comments
 (0)