Share one Markdown writer between the article exporters and escape properly #62

Closed
opened 2026-10-11 09:15:23 +02:00 by midas · 1 comment
Owner

Found in the codebase review (2026-10-11). The review fixed the actual bugs (entity decoding collapsed newlines, multi-paragraph blockquotes, empty quote authors); this is the remaining, larger cleanup.

Duplication: VolkskrantArticleExporter.buildMarkdown and GelderlanderArticleExporter.buildMarkdown repeat the header (title, intro, author and date, original link, ---), image + caption + credits, quote and list rendering. A shared markdown/MarkdownWriter keeps both in step. (Same for the identical private Filter class and isDropped in volkskrant/ContentFilters and gelderlander/GelderlanderContentFilters.)

Escaping gaps (cosmetic, but breaks rendering for some articles):

  • HtmlToMarkdown: literal *, _, [, ] and a leading #, - or N. aren't escaped; link text/URLs aren't escaped (a ) or space breaks the link); relative hrefs stay relative.
  • <b>foo </b> becomes **foo **, which CommonMark doesn't render as bold: move inner whitespace outside the markers.
  • Image captions and credits are appended raw (*caption* breaks on newlines or edge spaces); MarkdownVideo's *▶ title* caption isn't escaped. Volkskrant doesn't pass author/quote author through convert, Gelderlander does.

Small extras: GelderlanderArticleExporter caches up to 50 full ArticleDetailResponse trees (10-20 is plenty); JVM tests for KubusModels.value, ContentFilters.filterArticleBlocks and MarkdownVideo (an HtmlToMarkdownTest exists now).

Done when: one writer used by both exporters, unit tests cover escaping, and a device test copies a few articles (with lists, quotes, images, video) correctly in both apps.

Found in the codebase review (2026-10-11). The review fixed the actual bugs (entity decoding collapsed newlines, multi-paragraph blockquotes, empty quote authors); this is the remaining, larger cleanup. **Duplication:** `VolkskrantArticleExporter.buildMarkdown` and `GelderlanderArticleExporter.buildMarkdown` repeat the header (title, intro, author and date, original link, `---`), image + caption + credits, quote and list rendering. A shared `markdown/MarkdownWriter` keeps both in step. (Same for the identical private `Filter` class and `isDropped` in `volkskrant/ContentFilters` and `gelderlander/GelderlanderContentFilters`.) **Escaping gaps** (cosmetic, but breaks rendering for some articles): - `HtmlToMarkdown`: literal `*`, `_`, `[`, `]` and a leading `#`, `-` or `N.` aren't escaped; link text/URLs aren't escaped (a `)` or space breaks the link); relative `href`s stay relative. - `<b>foo </b>` becomes `**foo **`, which CommonMark doesn't render as bold: move inner whitespace outside the markers. - Image captions and credits are appended raw (`*caption*` breaks on newlines or edge spaces); `MarkdownVideo`'s `*▶ title*` caption isn't escaped. Volkskrant doesn't pass author/quote author through `convert`, Gelderlander does. **Small extras:** `GelderlanderArticleExporter` caches up to 50 full `ArticleDetailResponse` trees (10-20 is plenty); JVM tests for `KubusModels.value`, `ContentFilters.filterArticleBlocks` and `MarkdownVideo` (an `HtmlToMarkdownTest` exists now). **Done when:** one writer used by both exporters, unit tests cover escaping, and a device test copies a few articles (with lists, quotes, images, video) correctly in both apps.
Author
Owner

Device test v1.9.0-dev.11 (Volkskrant 7.52.0, De Gelderlander 9.21.1), installed over the previous local build: both start without crashes or VerifyErrors. Copy as Markdown checked on a Gelderlander article with video + image and a Volkskrant analysis with five inline links, subheads and an image: headings, intro quote, video embed (thumbnail URL encoding intact), captions/credits and links render correctly; no over-escaping. Remaining byline issues predate #66 and are tracked separately: Kubus author missing (not in Source), Volkskrant uses the byline description (bio) instead of the author name, and both print the publication date as raw ISO UTC.

Device test v1.9.0-dev.11 (Volkskrant 7.52.0, De Gelderlander 9.21.1), installed over the previous local build: both start without crashes or VerifyErrors. Copy as Markdown checked on a Gelderlander article with video + image and a Volkskrant analysis with five inline links, subheads and an image: headings, intro quote, video embed (thumbnail URL encoding intact), captions/credits and links render correctly; no over-escaping. Remaining byline issues predate #66 and are tracked separately: Kubus author missing (not in Source), Volkskrant uses the byline description (bio) instead of the author name, and both print the publication date as raw ISO UTC.
midas closed this issue 2026-10-11 14:01:58 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
midas/midas-patches#62
No description provided.