Repository navigation
Description
These defects were found while maintaining a downstream deployment of Docmost, which fixed them in its copy of packages/editor-ext/src/lib/prosemirror-docx. They are reported here because they are still present upstream. They are functional bugs, not security issues.
Versions checked
- Release v0.96.0 (tag commit
9b3e5dd3dc21588fa20c02c5b8646d2f46ee73af). mainatc1305f002e47ece4d40f0aebba75d8d0f762d8ea(2026-10-11), which adds table column widths, a fallback for unknown node types, and serializers for the tab nodes. None of these changes touches the code paths of the defects below.
How they were checked
The six TypeScript files of packages/editor-ext/src/lib/prosemirror-docx were transpiled unmodified and pageNodeToDocxBuffer was called on small ProseMirror documents, with docx 9.7.1 and image-dimensions 2.5.0. The resulting .docx packages were then unzipped and their word/document.xml, word/styles.xml, word/numbering.xml and [Content_Types].xml read. Both versions above gave identical output.
At v0.96.0, no file under apps/server calls pageNodeToDocxBuffer, so the probe calls it directly. Its image resolver was replaced by one that returns fixed bytes. Points 1 and 2 depend on what the real resolver returns, and say so. Statements about the supported formats of image-dimensions and about SVG and checkbox support in docx come from the installed package sources, not from the probe. How Word displays a package was not measured; statements about Word below are expectations unless they say otherwise.
1. SVG images and diagrams are dropped from the export
In the output. An image whose file is an SVG gets no ImageRun: the package has no media part for it and no wp:extent, so the reader gets no picture in its place. The same holds for the draw.io and Excalidraw diagrams, which the editor saves as SVG attachments (const fileName = "diagram.drawio.svg"; in drawio-view.tsx, const fileName = "diagram.excalidraw.svg"; in excalidraw-menu.tsx). This holds when the resolver returns the SVG bytes, as the probe's resolver did.
Why. renderImage in schema.ts sends drawio and excalidraw through the same path as image (drawio: renderImage,, excalidraw: renderImage,). In serializer.ts, image() asks image-dimensions for the size:
const dimensions = imageDimensionsFromData(buffer);
/* If the image is not a valid image, don't add it */
if (!dimensions) return;image-dimensions 2.5.0 reads PNG, GIF, JPEG, WebP, AVIF and HEIC. It does not read SVG, so the function returns undefined and image() returns before any ImageRun is created. Anything else that throws is silenced by the catch in renderImage (// Unrenderable/missing image: skip rather than fail the whole export.).
Suggested fix. docx 9.7.1 supports SVG images with type: 'svg', and it reads a raster fallback for every SVG image. When imageDimensionsFromData returns nothing, check whether the bytes are an SVG document. If they are, take its size from the width and height attributes of the root element, or from its viewBox. With neither, use the browser default of 300 × 150. Then place it:
new ImageRun({
type: 'svg',
data: buffer,
fallback: { type: 'png', data: placeholderPng },
transformation: { width, height },
});Word versions that support SVG should show the SVG itself, so the fallback would only be seen by readers that cannot render SVG. A one-pixel grey PNG stretched to the image size should do as the fallback. One practical note from the downstream fix: draw.io SVGs carried a long content attribute on the root element, so the root tag has to be read up to its closing >, not within a fixed number of bytes.
For an image that still cannot be placed, a short visible text such as "[Image not exported: unsupported format]" is more useful to the reader than a silent gap.
2. The image type is taken from the URL text, which gives odd media parts
In the output. If the image resolver returns bytes for a data: URI, the package contains media parts named after the whole URI. A downstream deployment reported that Word refused to open a package built this way. The probe did not open files in Word, so this report is not reproduced here. A WebP image produces a media part whose extension has no content type declared in the package.
Why. In image():
it = imageType || (src.replace(/.*\./, '').toLowerCase() as any);The "type" is whatever follows the last dot of src. docx then names the media part with it. Output from the probe:
- for
data:image/png;base64,…(a base64 string contains no dot), the type is the whole URI, and the package gets parts namedword/media/<hash>.data:image/andword/media/<hash>.data:image/png;base64,…; - for
…/photo.webp, the part isword/media/<hash>.webp, while[Content_Types].xmlonly declares the image extensionspng,jpeg,jpg,bmp,gifandsvg; - a query string after the file name (
photo.png?t=1) gives a part named<hash>.png?t=1. The editor itself writes such a suffix into thesrcof draw.io and Excalidraw nodes (?t=indrawio-view.tsxandexcalidraw-menu.tsx).
Upper-case extensions and .jpeg come out with a lower-case name and a declared type.
Suggested fix. Take the type from the bytes. The result of imageDimensionsFromData has a type field; in 2.5.0 it detects png, gif, jpeg, webp, avif and heic. Map it to the values docx accepts:
const DOCX_TYPES: Record<string, 'png' | 'jpg' | 'gif'> = { png: 'png', jpeg: 'jpg', gif: 'gif' };
const type = DOCX_TYPES[dimensions.type];
if (!type) { /* WebP, AVIF, HEIC: no declared content type; skip with a visible note */ }Note that the ImageType declared in serializer.ts (export type ImageType = 'jpg' | 'png' | 'gif' | 'bmp';) does not include jpeg, and nothing checks the extension against it at run time.
3. Every image is sized to 600 px and centered
In the output. From the code, renderImage calls state.image(src, 100), which sizes every image to the full MAX_IMAGE_WIDTH of 600 px (6.25 inches at 96 dpi). The probe confirms this for a 1 × 1 image whose node has width 40: the package holds <wp:extent cx="5715000" cy="5715000"/> (600 × 600 px) and <w:jc w:val="center"/>, although the node asked for left alignment.
Why. renderImage calls await state.image(src, 100);: 100 % of MAX_IMAGE_WIDTH (export const MAX_IMAGE_WIDTH = 600;), and never reads the node's width attribute. The align parameter of image() is never passed, so it keeps its default align: AlignOptions = 'center'.
Suggested fix. Read the node's width attribute (check the unit the editor stores for it), and fall back to the natural width from imageDimensionsFromData. Cap the result at maxImageWidth, which the serializer already divides by the column count inside tables. image() already derives the height from the aspect ratio, so keep that when the width changes. One CSS pixel is 9,525 EMU, the unit docx expects (600 px gives the 5715000 above). Pass the node's align through: image() takes left, right or center, and the default is center.
4. Quotes and callouts have no style of their own
In the output. A blockquote or a callout is a paragraph with a style that the document never defines. Word is expected to show it as body text. A callout's type (for example info or warning, which the editor menu sets) is not written at all.
Why. Both serializers pass a style that the document never defines:
async blockquote(state, node) {
await state.renderContent(node, { style: 'IntenseQuote' });
},and the same { style: 'IntenseQuote' } for callout, which does not read the node's type. word/document.xml gets <w:pStyle w:val="IntenseQuote"/>, but word/styles.xml has no w:styleId="IntenseQuote". The styles that docx 9.7.1 defines include the title, headings, Strong, ListParagraph, Hyperlink and the footnote and endnote styles, and not this one. Word is expected to fall back to the default paragraph style.
Defining the style is not enough on its own. renderContent applies its opts once per direct child, and the first paragraph that closes consumes it. In a callout made of an intro paragraph and a three-item bullet list, the probe shows only the intro and the first bullet with IntenseQuote; the second and third bullets get ListParagraph alone.
Suggested fix.
- Define the paragraph styles through the
stylesoption thatpageNodeToDocxBufferalready fills. The prosemirror-docx README showsparagraphStylesunderstyles. Examples: a left border and indent for the quote, and one style per callout type with its border and shading color. A style also lets the user restyle all quotes in Word at once. - Apply the style when each paragraph of the block closes, at any depth, not once per direct child. The downstream fix wraps
closeBlockfor the duration of the block'srenderContent, and leaves paragraphs that already carry a heading or a style untouched (see point 5). - Optionally, start a non-neutral callout with a bold label paragraph (for example "Warning"), since color alone is lost when printed in grayscale.
5. A heading inside a quote or callout produces a paragraph with two paragraph styles
In the output. The heading's paragraph carries two paragraph styles. The OOXML schema allows at most one w:pStyle in a paragraph's properties, so strict validators are expected to reject the file. How Word itself reacts was not measured.
Why. The { style: 'IntenseQuote' } option set by renderContent is merged with the { heading } passed by the heading serializer's closeBlock. The probe shows the first paragraph of a quote that opens with a heading as:
<w:pStyle w:val="Heading2"/><w:pStyle w:val="IntenseQuote"/>Suggested fix. When a paragraph already has a heading or a style, do not add the block's style to it. The heading then keeps its own style and sits outside the quote formatting, which avoids the duplicate element.
6. A list nested in a list of another kind gets the outer list's markers
In the output.
- An ordered list inside a bullet list gets level 1 of the bullet definition,
○, where numbers are expected. Word is expected to show bullets. - A bullet list inside an ordered list gets level 1 of the ordered definition,
lowerLetter(a., b.). - A task list uses the bullet definition as well (probed at the top level). A task list nested in an ordered list would take the ordered list's markers by the same code path (not probed).
- Several lists nested under different items of one outer list share one numbering instance: all six items in the probe's case had
numId2. Word is expected to continue the count from one nested list into the next (not probed). With an outer bullet list this is invisible, because every nested list shows bullets.
Why. renderList creates a numbering definition only for the outermost list. A nested list reuses that reference one level down and ignores its own style:
} else {
const { reference, level } = this.currentNumbering;
this.currentNumbering = { reference, level: level + 1 };
}Level 1 of the bullets definition is ○, and level 1 of numbered is LevelFormat.LOWER_LETTER. In the probe, an ordered list inside a bullet list gave <w:ilvl w:val="1"/><w:numId w:val="2"/> on a definition whose level 1 is <w:numFmt w:val="bullet"/>. A bullet list inside an ordered list gave level 1 lowerLetter. In the case with two ordered lists under two bullet items, all six items shared numId 2.
Suggested fix. Keep the style together with the current reference and level. When a nested list's style differs from the enclosing one, or for each new nested ordered list, push a new definition with createNumbering(createShortId(), style) and use it at level + 1. The definitions in numbering.ts already indent by level, so the nesting depth stays right. Restore the enclosing numbering when the nested list ends, as the current code does for the level.
7. Inline code asks for a generic font name that Word may not map to a monospace font
Why. The code mark asks for font: { name: 'Monospace' }, and the probe shows w:ascii="Monospace" in the output. Monospace is a generic family name that fontconfig resolves on Linux. To our knowledge, it is not the name of a font installed on a standard Windows or macOS system, so Word is expected to substitute a font of its own choosing. This was not measured in Word.
Suggested fix. Name a real font that Word users have, such as Consolas. Word then substitutes it if absent, as for any named font.
8. Formulas are written as their LaTeX source
In the output. An equation object is expected to show the raw source, for example \frac{a}{b}. The probe's document contains <m:t>\frac{a}{b}</m:t>.
Why. math() writes the LaTeX string into the equation as a run: new Math({ children: [new MathRun(latex)] }).
Suggested fix. Convert LaTeX to OMML before writing. One approach: render MathML with KaTeX (throwOnError: true, trust: false), keep only the presentation child of semantics, and translate the MathML tree element by element into docx components. If a formula fails to convert, keep the raw LaTeX in place. Building the OMML from components rather than XML strings keeps the formula text inside m:t and lets docx escape it.
9. Two smaller rendering choices
These are suggestions rather than bugs.
- Tasks. A task list is rendered as a bullet list whose items start with a text glyph (
state.text(node.attrs?.checked ? '☑ ' : '☐ ');). Each task is expected to show a bullet and a glyph that cannot be ticked.docx9.7.1 exportsCheckBoxandCheckBoxUtil, which write aw14:checkboxcontent control; Word is expected to let the reader tick it on click (not tested). - Collapsible blocks.
detailsSummaryis closed asHeadingLevel.HEADING_4(the probe showsHeading4), so every summary is expected to enter Word's navigation pane and table of contents. The content below it gets no paragraph style in the probe, so it is not set apart. A bold paragraph style withkeepNextfor the summary, and an indented style for the content, would match the expanded block in the editor without polluting the outline.
A downstream deployment has local fixes for points 1 to 5 and 7; they are not attached here. Points 6 and 8 are described as approaches only.
Activity