Skip to content

Import Word List styles as 1-3 lists, keep line breaks - #174

Merged
krperry merged 1 commit into
mainfrom
list-style-fix
Oct 18, 2026
Merged

krperry merged 1 commit into
mainfrom
list-style-fix

Conversation

@krperry

@krperry krperry commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

Problem

DOCX files whose paragraphs use Word's "List" style (for example the
address block at the top of bank statements) were imported as normal
paragraphs and formatted 3-1, starting in cell 3. They should be list
items formatted 1-3. Line breaks inside list items were also dropped.

Changes

bbx.lua

  • getCustomStyle never worked under Pandoc 3: attributes arrive as
    an AttributeList userdata, not a table, so the existing Div
    handler for custom list styles never ran. It now reads the
    attribute directly.
  • Word's unnumbered list styles (List, List 2..List 9,
    List Continue, List Continue 2..9) become bullet-less list
    items (L1-3). Adjacent items are merged into one list by
    FixNestedList. Other paragraphs stay Body Text (3-1).
  • New listItemText keeps utd:newLine line breaks inside list
    items (trimming leading/trailing ones). Used for styled, bullet
    and ordered list items; previously removeTags stripped them.

FixNestedList.kt

  • moveListItems was called for every child element of a list item
    and removed any empty child, such as utd:newLine. It now only
    runs for nested lists.

"List Paragraph" behaviour is unchanged (still a bulleted list via
list-paragraph-style.lua).

Tests

New PandocDocxListStyleTest, using a sample statement DOCX:

  • address/summary lines import as LIST_ITEM with style L1-3, merged
    into one list, no bullets added
  • line breaks are kept in styled and bullet list items
  • nested lists still flatten to itemLevel 1
  • plain, "Body Text" and "Listing" paragraphs stay Body Text

PandocLuaDefinitionListTest still passes. The full build also
needs #173 for two unrelated UI test failures already on main.

DOCX paragraphs styled "List" (and "List 2".."List 9", "List
Continue") were imported as ordinary paragraphs, so addresses on
statements were formatted 3-1 instead of as 1-3 list items.

bbx.lua already had a Div handler for custom list styles, but it
never ran: Pandoc 3 passes classic-writer attributes as an
AttributeList userdata, not a table, so getCustomStyle always
returned nil. Read the attribute directly and treat Word's
unnumbered list styles as bullet-less list items. FixNestedList
merges the adjacent items into one list. Other paragraphs are
unchanged and stay Body Text.

Line breaks inside list items were also lost in two places:
- bbx.lua stripped every utd tag, including utd:newLine, when
  building list items. Add listItemText, which keeps inner breaks
  and trims leading/trailing ones, and use it for styled, bullet
  and ordered list items.
- FixNestedList called moveListItems on every child element of a
  list item, which removed any empty child such as utd:newLine.
  Only move actual nested lists.

Add PandocDocxListStyleTest with a sample statement document to
cover list styles, line breaks, nested list flattening and that
plain paragraphs stay Body Text.
@krperry
krperry merged commit 36bc403 into main Oct 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant