<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: smartias</title>
    <description>The latest articles on DEV Community by smartias (@smartias).</description>
    <link>https://dev.to/smartias</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4132314%2Ffbfddfd4-c1f5-4da2-b277-ce787e4ce998.png</url>
      <title>DEV Community: smartias</title>
      <link>https://dev.to/smartias</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/smartias"/>
    <language>en</language>
    <item>
      <title>The Four Ways Your Word Template Silently Breaks</title>
      <dc:creator>smartias</dc:creator>
      <pubDate>Sat, 19 Sep 2026 03:42:15 +0000</pubDate>
      <link>https://dev.to/smartias/the-four-ways-your-word-template-silently-breaks-4cff</link>
      <guid>https://dev.to/smartias/the-four-ways-your-word-template-silently-breaks-4cff</guid>
      <description>&lt;p&gt;If you've ever generated a Word document from a template — a proposal, a&lt;br&gt;
contract, a report — you've probably hit a moment where the output looks&lt;br&gt;
subtly wrong and you can't figure out why. The numbering restarts partway&lt;br&gt;
through a list that should be continuous. A heading's spacing just... isn't&lt;br&gt;
applied, even though you can see the setting in the XML. A stray blank page&lt;br&gt;
shows up at the end of every document, no matter how many times someone&lt;br&gt;
"fixes" it in Word.&lt;/p&gt;

&lt;p&gt;None of these are bugs in Word, and none of them are bugs in whatever&lt;br&gt;
templating tool you're using to fill the document. They're structural&lt;br&gt;
defects that have been silently baked into the template file itself, often&lt;br&gt;
years before anyone noticed — and because they're silent, they survive&lt;br&gt;
every round of manual "fix it in Word" edits, because a human editing in&lt;br&gt;
Word can't see the XML that's actually broken.&lt;/p&gt;

&lt;p&gt;Here are the four I've run into most.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Trailing blank pages that keep coming back
&lt;/h2&gt;

&lt;p&gt;Every time a document gets saved, edited, and saved again, there's a good&lt;br&gt;
chance an empty paragraph or two gets left behind at the end — someone&lt;br&gt;
pressed enter once too many, or a section got deleted but its terminal&lt;br&gt;
paragraph mark didn't. Individually harmless. Accumulated over a few years&lt;br&gt;
of template maintenance, you get two or three blank pages tacked onto the&lt;br&gt;
end of every document generated from it, and "just delete the blank&lt;br&gt;
paragraphs" doesn't stick because the next person who edits the template&lt;br&gt;
adds a couple more without noticing.&lt;/p&gt;

&lt;p&gt;The fix is mechanical once you know what to look for: a run of two or more&lt;br&gt;
empty &lt;code&gt;&amp;lt;w:p&amp;gt;&lt;/code&gt; elements immediately before the body's closing &lt;code&gt;&amp;lt;w:sectPr&amp;gt;&lt;/code&gt;.&lt;br&gt;
(One trailing empty paragraph is normal — every section conventionally ends&lt;br&gt;
with one. It's a &lt;em&gt;run&lt;/em&gt; of them that's the defect.)&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Paragraph properties that Word quietly ignores
&lt;/h2&gt;

&lt;p&gt;This one's the most surprising once you see it. Inside a paragraph's&lt;br&gt;
&lt;code&gt;&amp;lt;w:pPr&amp;gt;&lt;/code&gt; element, the paragraph-mark run properties (&lt;code&gt;&amp;lt;w:rPr&amp;gt;&lt;/code&gt;) have to be&lt;br&gt;
the &lt;em&gt;last&lt;/em&gt; child, per the OOXML spec (ECMA-376 §17.3.1.29). If anything —&lt;br&gt;
spacing, indentation, a numbering reference — comes after it, Word doesn't&lt;br&gt;
error. It doesn't warn. It just ignores that element entirely, as if it were&lt;br&gt;
never there.&lt;/p&gt;

&lt;p&gt;This happens constantly in practice because the natural way to "add a pPr&lt;br&gt;
setting" programmatically is to insert it right before &lt;code&gt;&amp;lt;/w:pPr&amp;gt;&lt;/code&gt; — and that&lt;br&gt;
silently breaks the moment an &lt;code&gt;&amp;lt;w:rPr&amp;gt;&lt;/code&gt; is already present, which it usually&lt;br&gt;
is. You end up with a heading style that visibly has the right spacing&lt;br&gt;
value in the XML, and visibly doesn't apply it in Word, and there's no error&lt;br&gt;
message anywhere pointing at why.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Lists that restart for no visible reason
&lt;/h2&gt;

&lt;p&gt;A numbered list in a Word document doesn't carry its own counter — it&lt;br&gt;
references a &lt;code&gt;&amp;lt;w:num&amp;gt;&lt;/code&gt; entry in &lt;code&gt;numbering.xml&lt;/code&gt;, and that &lt;code&gt;&amp;lt;w:num&amp;gt;&lt;/code&gt; entry&lt;br&gt;
points at an abstract list definition (&lt;code&gt;&amp;lt;w:abstractNum&amp;gt;&lt;/code&gt;) that actually&lt;br&gt;
defines the numbering format and start value. Word tracks the running count&lt;br&gt;
&lt;em&gt;per &lt;code&gt;&amp;lt;w:num&amp;gt;&lt;/code&gt; entry&lt;/em&gt;, not per abstract definition.&lt;/p&gt;

&lt;p&gt;So here's the failure mode: someone copies a numbered paragraph from one&lt;br&gt;
part of the template to another — maybe via copy-paste, maybe Word's own&lt;br&gt;
"repair" behavior on document merge — and Word (or the person's editing&lt;br&gt;
tool) creates a &lt;em&gt;second&lt;/em&gt; &lt;code&gt;&amp;lt;w:num&amp;gt;&lt;/code&gt; entry pointing at the same abstract list.&lt;br&gt;
Visually, nothing looks different. The list still looks like one continuous&lt;br&gt;
numbered list in the editor. But because it's now split across two &lt;code&gt;&amp;lt;w:num&amp;gt;&lt;/code&gt;&lt;br&gt;
references, the count resets in the middle, and nobody can figure out why&lt;br&gt;
item 8 is suddenly item 1 again.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Merge tokens that vanish for no reason
&lt;/h2&gt;

&lt;p&gt;If you're generating documents by find-and-replacing tokens like&lt;br&gt;
&lt;code&gt;{{PROJECT_NAME}}&lt;/code&gt; directly against the raw XML, you'll eventually hit a&lt;br&gt;
token that just doesn't get replaced — even though it's clearly sitting&lt;br&gt;
right there in the document when you open it in Word.&lt;/p&gt;

&lt;p&gt;The reason: Word splits a paragraph's visible text across multiple &lt;code&gt;&amp;lt;w:r&amp;gt;&lt;/code&gt;&lt;br&gt;
run elements for reasons that have nothing to do with what's on screen —&lt;br&gt;
spell-check markers, revision tracking IDs, just the accumulated history of&lt;br&gt;
edits. So &lt;code&gt;{{PROJECT_NAME}}&lt;/code&gt; might actually be stored as &lt;code&gt;{{PROJECT_&lt;/code&gt; in one&lt;br&gt;
run and &lt;code&gt;NAME}}&lt;/code&gt; in the very next one. On screen, one word. In the XML, two&lt;br&gt;
separate &lt;code&gt;&amp;lt;w:t&amp;gt;&lt;/code&gt; elements that a naive string search across a single run&lt;br&gt;
will never match.&lt;/p&gt;

&lt;p&gt;This one isn't really fixable as a "repair" — merging runs back together is&lt;br&gt;
a formatting decision, not a structural correction — but it's absolutely&lt;br&gt;
worth &lt;em&gt;detecting&lt;/em&gt; before it silently eats a field in production.&lt;/p&gt;




&lt;p&gt;All four of these share the same shape: invisible in the Word UI, silent&lt;br&gt;
(no error, no warning) when they cause a problem, and they accumulate&lt;br&gt;
because nobody can see them to fix them permanently. That's the actual gap&lt;br&gt;
— not a shortage of tools that can &lt;em&gt;fill&lt;/em&gt; a Word template, but a shortage of&lt;br&gt;
tools that can tell you a template is already damaged before you build&lt;br&gt;
anything on top of it.&lt;/p&gt;

&lt;p&gt;That's what &lt;a href="https://github.com/smartias/docx-doctor" rel="noopener noreferrer"&gt;docx-doctor&lt;/a&gt; does.&lt;br&gt;
&lt;code&gt;docx-doctor scan your-template.docx&lt;/code&gt; finds all four patterns, with &lt;code&gt;--ci&lt;/code&gt;&lt;br&gt;
support so a broken template fails a build instead of shipping.&lt;/p&gt;

&lt;p&gt;It's grown a second half since I first wrote this: &lt;code&gt;docx-doctor/build&lt;/code&gt;, a&lt;br&gt;
small API for constructing a &lt;em&gt;new&lt;/em&gt; document instead of repairing an old&lt;br&gt;
one — where three of these four defects are structurally impossible to&lt;br&gt;
produce in the first place, not just detectable afterward. A paragraph&lt;br&gt;
builder that always puts the paragraph-mark properties last. A list helper&lt;br&gt;
where "continue this list" and "start a new one" are different,&lt;br&gt;
deliberately-named calls, so the numbering-restart bug can't happen by&lt;br&gt;
accident. A token helper that's guaranteed to never fragment across runs.&lt;br&gt;
If you're generating documents from scratch rather than inheriting a&lt;br&gt;
decade-old template, that's the more useful half now.&lt;/p&gt;

&lt;p&gt;It's on npm (&lt;code&gt;npx docx-doctor scan template.docx&lt;/code&gt;), MIT licensed, still&lt;br&gt;
growing. If you've got a real damaged template lying around, that's the&lt;br&gt;
most useful thing you could send me.&lt;br&gt;
``&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>opensource</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
