RTF reader: support legacy \pn/\pntext paragraph numbering (#11686).

Word-95-style numbered and bulleted lists are encoded with a
`{\pntext ...}` auto-number destination at the start of each list
paragraph plus a `{\*\pn ...}` destination describing the numbering,
rather than the modern `\listtext`/`\listtable` mechanism.  Two problems:

1. The `\pntext` marker text ("1.", "·", etc.) was captured as the
   paragraph's first text run, which sits before the paragraph's
   `\ls`/`\ilvl`, so emitBlocks (which reads list properties from the first
   run) misclassified the paragraph as an ordinary paragraph.  The first
   item of each list therefore came out as a stray paragraph.

2. The numbering style was ignored, so numbered lists defaulted to
   bullets.

Treat `\pntext` like `\listtext`: drop its visible marker text and flag the
start of a new list item.  Parse the `{\*\pn ...}` destination
(`\pnlvlbody`/`\pnlvlblt`, `\pndec`, `\pnucltr`, `\pnlcltr`,
`\pnucrm`, `\pnlcrm`, `\pnstart`, and the `\ls`/`\ilvl` keys it
carries) into the list override table so numbered lists are
emitted as ordered lists with the right number style.

`\pn` is a paragraph property that remains in effect until reset
by `\pard`, auto-numbering every paragraph in scope. Track
this (`sPnActive`) so each paragraph becomes its own list item,
rather than merging markerless continuation paragraphs as is done
for modern `\listtext` lists.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
John MacFarlane
2026-06-08 22:28:35 +00:00
parent 888a0062f1
commit 3a5f7ecee1
4 changed files with 86 additions and 5 deletions
+1
View File
@@ -36,6 +36,7 @@ tests = map rtfTest [ "footnote"
, "list_simple"
, "list_complex"
, "list_multiparagraph"
, "list_legacy"
, "bookmark"
, "table_simple"
, "table_error_codes"
+14
View File
@@ -0,0 +1,14 @@
Pandoc
Meta { unMeta = fromList [] }
[ OrderedList
( 1 , Decimal , Period )
[ [ Para [ Str "A" ] ]
, [ Para [ Str "Numbered" ] ]
, [ Para [ Str "List" ] ]
]
, BulletList
[ [ Para [ Str "A" ] ]
, [ Para [ Str "Bulleted" ] ]
, [ Para [ Str "List" ] ]
]
]
+4
View File
@@ -0,0 +1,4 @@
{\rtf1\ansi\deff0{\fonttbl{\f0 Helvetica;}{\f2 Symbol;}{\f3 Symbol;}}
\plain\plain\f0\fs20\pard\ssparaaux0\s0{\pntext\pard\plain\f2\fs22 1.\tab}{\*\pn\pnlvlbody\pnstart1\pndec\ls3\ilvl0\pnhang{\pntxta \'2e}}\ls3\ilvl0\fi-360\li360\ql\plain\f0\fs20 A\par Numbered\par List\par
\pard\ssparaaux0\s0{\pntext\pard\plain\f3\fs22 \'b7\tab}{\*\pn\pnlvlblt\ls5\ilvl0\pnhang\pnf3{\pntxtb \'b7}}\ls5\ilvl0\fi-360\li360\ql\plain\f0\fs20 A\par Bulleted\par List\par
}