Skip to content

Highlight export uses invalid OOXML: w:highlight instead of w:shd for custom colors #2124

@dcf1recodelaw

Description

@dcf1recodelaw

Bug Description

When applying text highlighting with custom colors (e.g. #FFEB3B) via the VS Code extension's formatText command, the DOCX export produces invalid OOXML that is silently ignored by Microsoft Word.

Current Behavior

SuperDoc exports highlighting as:

<w:highlight w:color="auto" w:val="clear" w:fill="FFEB3B" />

This is invalid OOXML. The <w:highlight> element (§17.3.2.17 of OOXML spec) only accepts predefined color names (yellow, green, cyan, magenta, etc.) via w:val. It does not support w:fill or w:color attributes.

Result: Microsoft Word silently ignores the element and no highlighting is displayed.

Expected Behavior

For custom (non-predefined) highlight colors, SuperDoc should export using <w:shd> (shading) instead:

<w:shd w:val="clear" w:color="auto" w:fill="FFEB3B" />

This is the standard OOXML approach for custom background colors on text runs and is correctly rendered by Microsoft Word.

For predefined colors, <w:highlight w:val="yellow" /> (etc.) would also be acceptable.

Steps to Reproduce

  1. Open a .docx file in the SuperDoc VS Code extension
  2. Apply highlighting via the programmatic API:
    {"command":"formatText","args":{"highlight":"#FFEB3B","scope":{"from":103,"to":124}}}
    (Or apply highlighting manually in the webview editor)
  3. Wait for auto-save
  4. Open the saved .docx in Microsoft Word
  5. Observe: no highlighting is visible

Workaround

Post-process the exported DOCX by replacing <w:highlight w:fill="..."> elements with <w:shd w:val="clear" w:color="auto" w:fill="..."> in word/document.xml.

Environment

  • SuperDoc VS Code Extension v0.1.0 (Lawvable fork)
  • macOS 15
  • VS Code (latest)
  • Microsoft Word for Mac

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions