Skip to content

Draw Markdown block quotes with a bar and a background - #1133

Open
KnifeLemon wants to merge 1 commit into
mainfrom
fix/markdown-blockquote-pdf
Open

KnifeLemon wants to merge 1 commit into
mainfrom
fix/markdown-blockquote-pdf

Conversation

@KnifeLemon

Copy link
Copy Markdown
Owner

Fixes #1098

Cause

Markdown → PDF is the HWPX writer followed by rhwp (MarkdownReader, not the markdown engine, which only does HTML and TXT). The quote wasn't lost in parsing: the issue's line (with its leading space), a quote at the very start, a BOM, front matter, CRLF and nested quotes all come out of Markdig as QuoteBlock.

MarkdownReader then mapped a quote to HParaFormat(Left: 2000) and nothing else. On the page that is a paragraph indented by 7 mm, which is what the reporter's screenshot shows.

Fix

  • HParaFormat gets LeftBar and Fill, and MarkdownReader sets them on a quote's paragraphs. Definition lists use the same indent and stay without a bar.
  • HWPX: a paragraph border (hh:border pointing at a borderFill with only a left line), connected across paragraphs. rhwp draws it, and 한글 reads it as a normal paragraph border.
  • DOCX: w:pBdr and w:shd, in CT_PPr's order.
  • The indent stays, so MarkdownWriter still turns it back into > . Writers that don't know the new fields (EPUB, FB2, text) are unchanged.

How it looks in rhwp

  • Nested quotes share one bar at the column's edge, with the text indented per level. rhwp draws a paragraph box from the column's edge whatever the indent; 한글 should put the bar at each level's indent (not opened in 한글 or Word here).
  • rhwp paints the background over half of the bar, so the bar is 1 mm wide to stay visible.
  • Code blocks and tables inside a quote keep their indent but get no bar: they aren't paragraphs.

Tests

In MarkdownTests: the reader (six ways a quote can open a file, nesting, a definition list stays bar-free), the HWPX and DOCX output, and the PDF itself (rhwp, then pixels: background and a bar taller than a line).

MarkdownTests, DocxWriterTests and HwpxReaderTests: 46 passed, 1 skipped (LibreOffice isn't installed here). With the reader's old mapping restored, the 9 reader, HWPX and DOCX cases fail. The PDF test failed in that run too, but on an rhwp timeout rather than its assertion, so that one isn't proven red; a direct rhwp export of the same document shows no bar or background without the change.

rhwp was very slow to start from the test host on this loaded machine (several did not finish within 127 s, including the existing Markdown_to_pdf_with_built_in_engines, with the process idle at 3 MB). Run directly it takes seconds, and the tests pass on a retry.

🤖 Generated with Claude Code

Markdown parsed every quote correctly, with a BOM, front matter, CRLF or
nesting too, but the reader only turned it into a left indent. In a PDF that
is a slightly indented paragraph, which nobody reads as a quote.

A quote's paragraphs now carry a left bar and a faint background, written as
a paragraph border in HWPX, which rhwp draws, and as w:pBdr and w:shd in DOCX.
The indent stays, so the Markdown writer still reads it back as a quote.

Fixes #1098

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

md 转pdf 格式问题

1 participant