Hacker News new | ask | show | jobs
by Jap2-0 1512 days ago
Rewritten for clarity (and because I now actually know what's happening):

If you look at the XML (change .docx to .zip) in styles.xml you see the declaration of the style "BodyText3":

  <w:style w:type="paragraph" w:styleId="BodyText3"><w:name w:val="Body Text 3"/><w:basedOn w:val="Normal"/><w:semiHidden/><w:rPr><w:rFonts w:ascii="Wingdings" w:hAnsi="Wingdings"/><w:i/><w:iCs/><w:strike/><w:color w:val="FF0000"/><w:sz w:val="52"/></w:rPr></w:style>
The first line ("paragraph") has its style set to "BodyText3", but also has formatting on that section of text itself, overriding it. Once the lines are joined into one paragraph, the paragraph formatting appears in the second part because that text does not have a style to override it.
3 comments

Steps to reproduce:

1. Create a Word document (most likely using the Blank document template, Normal.dotm)

2. Type text of first line; press Enter; type text of second line (technically Word calls these 'paragraphs'--Shift+Enter inserts a newline within the same paragraph)

3. Place cursor on first paragraph

4. Click a Paragraph Style from the Styles ribbon section to apply it (e.g., the second one, No Spacing)

5. Right click the style; choose Modify...

6. Change the formatting (e.g., the font to Wingdings)

7. Confirm the dialog

8. Select the entire first paragraph (doesn't matter whether you include the end-of-paragraph/newline)

9. Use manual formatting to override your changes to the style so the text matches the default style, Normal (e.g. use the listbox in the ribbon to change the font back to Calibri)

Done; if you now delete the newline, the second paragraph merges with the first and takes on its style, as parent points out.

Styles are the "proper" way to format Word documents (interesting to see what fraction of users actually use them). They're like a mix of HTML tags and styles: each paragraph (div) must have exactly one Paragraph Style, and each span of text can only have one Character Style. "Manual" formatting has highest precedence, followed by Character Style, followed by Paragraph Style. The benefits are the same as in HTML: semantic correctness and easy restyling of the entire document (e.g., by applying Themes from the Design tab). This sequence of steps is a fairly good demonstration of how they're used.

Edit: clarify

Just to clarify, this is not how I created the original document in 2004 :-) There were certainly no paragraph styles involved, and the edit actions had to include an undo, or it wouldn't happen. There was also no style inspector yet.
This is why I prefer just writing html/markdown and letting pandoc generate docx. Fiddling with the Word GUI when I know what I want and how to type it is just frustrating.
Just noticed that with this method, the backspace joins the two lines, whereas in the original it reveals the markup, but the newline between the lines remains.
Cool! This was pre-XML Word, and since introducing it became impossible at some point, I always just figured it had been a bug. Probably the bug was only in the creation, as I do remember the sequence of edit actions made no sense. I think it even had to include an undo.
So... Working as intended then, seems like.

This kind of thing can be easily debugged using the style inspector, "reveal formatting" which shows the formatting applied to the selected text and whether it's from paragraph formatting or direct text formatting.