feat(dpg): copy / share article as Markdown #52

Closed
opened 2026-10-10 15:47:58 +02:00 by midas · 1 comment
Owner

feat: copy / share article as Markdown in DPG apps

Part of #16. Affects both DPG Edition (de Volkskrant, AD, Trouw, Het Parool) and Kubus (De Gelderlander, De Stentor, Tubantia, ED, BD, BN DeStem, PZC).

Feature description

Add an option/button to copy or share articles as formatted Markdown in DPG news apps.
The exported Markdown should capture the full article structure:

  • Article title (# Title)
  • Lead / Intro (> *Intro*)
  • Byline & publication metadata (author, publication date, source brand, canonical URL)
  • Body paragraphs with inline formatting preserved (bold, italic, links)
  • Subheadings (## Heading)
  • Blockquotes and pullquotes (> Quote + author)
  • Image links with captions and credits (![Caption](URL))
  • Lists and Q&A blocks

This enables readers to easily archive, take notes (in e.g. Obsidian, Logseq, Notion) or share cleanly formatted articles without ad clutter.


Technical findings & architecture

DPG Media operates two distinct Android news platforms across its titles (see docs/apps/gelderlander.md#platform-guide-recognizing-dpg-edition-vs-kubus):

1. DPG Edition Platform (de Volkskrant, AD, Trouw, Het Parool)

Researched on de Volkskrant (be.persgroep.android.news.mobilevk) 7.52.0.

  • Architecture: Pure Jetpack Compose (nl.persgroep.edition.*), unobfuscated Kotlin classes with full metadata.
  • Article domain model: nl.persgroep.edition.article.domain.model.Article:
    • header: nl.persgroep.edition.article.domain.model.Header (BasicHeader, PlusHeader, ColumnHeader):
      • title: HeaderTitle(text = ...)
      • intro: HeaderIntro(text = ...)
      • byline: HeaderByline(authorByline = ...)
      • media: HeaderMedia.Image(image = ...) (header lead image)
    • body: List<nl.persgroep.edition.article.domain.model.Block>:
      • Block.ParagraphBlock(content: String): body text with HTML formatting (<b>, <i>, <a href="...">, <p>). Rendered via HtmlTextKt.
      • Block.SubHeaderBlock(content: String): section subheaders.
      • Block.ImageBlock(image: Image): image.akamaiImage.url, image.caption, image.credits, image.alt.
      • Block.QuoteBlock(content: String, author: String, organisation: String).
      • Block.ListBlock, Block.QuestionBlock, Block.AnswerBlock.
    • publication: Publication(publicationDate = ...)
    • url: canonical web URL (String).
  • Where the Article is created:
    • nl.persgroep.edition.article.data.converters.ArticleDtoMapper.invoke(ArticleDto): Article.
    • In ArticleViewModel: getCurrentArticle(): Article? returns this domain model.
  • Current share flow:
    • Floating bottom bar ArticleBottomToolbar / ActionPill renders action icons (ToolbarViewData.ToolbarAction.Share).
    • Handled by ArticleToolbarDelegateImpl.onShareClicked(ToolbarState.ArticleToolbar) which emits ShareEvent.ViewData(shareTitle, shareMessage).
    • Handled in MainActivity.handleIntentEvent(NavigationEvent.Intent.Share) -> getIntentNavigator$app().share(this, shareViewData).
    • Crucial note: ToolbarState.ArticleToolbar and ShareEvent.ViewData currently only contain the article title and URL; they do not carry the body blocks. The full article object lives in ArticleDtoMapper / ArticleViewModel.

2. Kubus Platform (De Gelderlander, De Stentor, Tubantia, ED, BD, etc.)

Researched on De Gelderlander (com.mecom.gelderlander.nl) 9.21.1.

  • Architecture: Hybrid Fragment + Compose (com.p000kubusapp.*). R8 obfuscates app code into defpackage, but keeps network Moshi models in com.kubus.module.network.model.* unobfuscated.
  • Network model: com.kubus.module.network.model.ArticleDetailResponse:
    • metadata: com.kubus.module.network.model.Metadata (title, author, url, publicationDate, etc.).
    • components: List<com.kubus.module.network.model.ArticleComponent>:
      • Paragraph(properties: Paragraph.Properties): properties.getContent() (HTML formatted string).
      • Title(properties: Title.Properties).
      • Intro(properties: Intro.Properties).
      • SubHeader(properties: SubHeader.Properties).
      • PictureComponent(properties: PictureComponent.Properties): properties.getUrl(), properties.getCaption(), properties.getSource().
      • Quote(properties: Quote.Properties): properties.getContent(), properties.getAuthor().
      • ListComponent, Question, Answer.
  • Presentation model & mapper:
    • r20.b() maps ArticleDetailResponse to j20(componentsList: List<i30>, metadata: y30, presentation: t40).
    • Component mapping happens in g20.a(ArticleComponent): i30 and g20.b(List<ArticleComponent>): List<i30>.
  • Current share flow:
    • Top toolbar in ArticlePagerFragment -> navigation flow emits n50.c(j20) (ShareArticle).
    • Handled by ArticlePagerFragment.V0(j20 articleDetail) -> calls ha2.h(Context, j20).
    • ha2.h(Context, j20) constructs Intent.ACTION_SEND with title + "\n\n" + url and calls context.startActivity(Intent.createChooser(...)).
    • Crucial note: j20 passed to ha2.h has j20.getMetadata() and j20.c() (presentation components List<i30>), while ArticleDetailResponse has the original unobfuscated Moshi components.

Markdown formatter design (extensions/extension)

Create a shared formatter in Java (e.g. nl.midasvo.extension.markdown.ArticleMarkdownFormatter):

  1. HTML parser / sanitizer:
    • Lightweight regex or char-scanner converting inline tags without external dependencies:
      • <b>, <strong> -> **...**
      • <i>, <em> -> *...*
      • <a href="(url)">(text)</a> -> [(text)]((url))
      • <br>, <p>, </p> -> newlines
      • HTML entity decoding (&amp; -> &, &quot; -> ", &#39; -> ', &lt; -> <, &gt; -> >, &nbsp; -> ).
      • Strip unsupported tags (<span>, <div>, etc.).
  2. Template structure:
    # {Title}
    
    > *{Intro}*
    
    *{Author} • {PublicationDate}*
    [Origineel artikel]({Url})
    
    ---
    
    {Body blocks formatted in order}
    
  3. Block formatting rules:
    • SubHeader: \n\n## {text}\n\n
    • Paragraph: \n\n{formattedText}\n\n
    • Quote: \n\n> "{quote}"\n> — *{author}*\n\n
    • Image: \n\n![{caption}]({imageUrl})\n*{caption} (Beeld: {credits})*\n\n
    • List: bullet points * {item}\n
    • Q&A: ### {question}\n\n{answer}\n\n

UI / UX options to trigger the action

Consider the following three options:

  • Instead of immediately sharing only the URL link when tapping the native share button:
    • If the Midas toggle is active, show an Android Chooser / BottomSheet dialog or directly enhance the share:
      1. "Kopieer als Markdown": puts the markdown string into ClipboardManager and displays a short Toast: "Artikel gekopieerd als Markdown".
      2. "Deel als Markdown": launches ACTION_SEND with the full Markdown text in EXTRA_TEXT.
      3. "Deel link": launches the original ACTION_SEND with just title + URL.
    • Advantage: Zero UI layout modifications required, works identically on all phone screen sizes and orientations.

Option B: Dedicated in-app button

  • de Volkskrant: Append a Copy action to ToolbarViewState.Content's actions list in createToolbarArticleContent, or add a button above/below the article.
  • De Gelderlander: Replace the space where ShareButtons were removed (at the bottom of the article body) with a styled "Kopieer als Markdown" button, or add a menu item in the top bar.

Option C: Long-press on Share button

  • Short tap = normal link share.
  • Long press = copy formatted Markdown to clipboard.

Proposed implementation steps

  1. Extension module (extensions/extension):
    • Implement ArticleMarkdownFormatter: unit-tested standalone conversion logic.
    • Implement MidasArticleStore: holds the latest active article data (or directly converts during hook).
    • Implement MidasShareHelper: handles clipboard copy (ClipboardManager) with Toast, and/or launches custom chooser.
    • Add BooleanSetting COPY_ARTICLE_MARKDOWN = new BooleanSetting("copy_article_markdown", true) to MidasSettings.java.
  2. DPG Edition patch (volkskrant):
    • Cache Article when created in ArticleDtoMapper.invoke(ArticleDto): Article (or in ArticleRepositoryImpl.fetchArticle).
    • Hook ArticleToolbarDelegateImpl.onShareClicked or MainActivity.handleIntentEvent(NavigationEvent.Intent.Share): pass the cached article to MidasShareHelper.
  3. Kubus patch (gelderlander):
    • Cache article components when ArticleDetailResponse is mapped, or hook ha2.h(Context, j20):
    • In ha2.h: inspect j20, extract content (or retrieve cached Moshi components), and delegate to MidasShareHelper.
  4. Midas Settings registration:
    • Register toggle Artikel als Markdown kopiëren/delen (copy_article_markdown, category "Artikelen", default on).
  5. Documentation:
    • Update docs/apps/volkskrant.md and docs/apps/gelderlander.md with findings and hook points.

Definition of done

  • .\gradlew.bat buildAndroid passes.
  • .\scripts\patch-install.ps1 -NoInstall applies on both apps.
  • Device test (with user confirmation): copying/sharing produces clean Markdown with intact formatting and image URLs.
  • Midas Settings toggle enables/disables the feature.
  • Documented in docs/apps/volkskrant.md and docs/apps/gelderlander.md.
# feat: copy / share article as Markdown in DPG apps Part of #16. Affects both DPG Edition (de Volkskrant, AD, Trouw, Het Parool) and Kubus (De Gelderlander, De Stentor, Tubantia, ED, BD, BN DeStem, PZC). ## Feature description Add an option/button to copy or share articles as formatted Markdown in DPG news apps. The exported Markdown should capture the full article structure: - Article title (`# Title`) - Lead / Intro (`> *Intro*`) - Byline & publication metadata (author, publication date, source brand, canonical URL) - Body paragraphs with inline formatting preserved (bold, italic, links) - Subheadings (`## Heading`) - Blockquotes and pullquotes (`> Quote` + author) - Image links with captions and credits (`![Caption](URL)`) - Lists and Q&A blocks This enables readers to easily archive, take notes (in e.g. Obsidian, Logseq, Notion) or share cleanly formatted articles without ad clutter. --- ## Technical findings & architecture DPG Media operates two distinct Android news platforms across its titles (see `docs/apps/gelderlander.md#platform-guide-recognizing-dpg-edition-vs-kubus`): ### 1. DPG Edition Platform (de Volkskrant, AD, Trouw, Het Parool) Researched on de Volkskrant (`be.persgroep.android.news.mobilevk`) 7.52.0. - **Architecture:** Pure Jetpack Compose (`nl.persgroep.edition.*`), unobfuscated Kotlin classes with full metadata. - **Article domain model:** `nl.persgroep.edition.article.domain.model.Article`: - `header`: `nl.persgroep.edition.article.domain.model.Header` (`BasicHeader`, `PlusHeader`, `ColumnHeader`): - `title`: `HeaderTitle(text = ...)` - `intro`: `HeaderIntro(text = ...)` - `byline`: `HeaderByline(authorByline = ...)` - `media`: `HeaderMedia.Image(image = ...)` (header lead image) - `body`: `List<nl.persgroep.edition.article.domain.model.Block>`: - `Block.ParagraphBlock(content: String)`: body text with HTML formatting (`<b>`, `<i>`, `<a href="...">`, `<p>`). Rendered via `HtmlTextKt`. - `Block.SubHeaderBlock(content: String)`: section subheaders. - `Block.ImageBlock(image: Image)`: `image.akamaiImage.url`, `image.caption`, `image.credits`, `image.alt`. - `Block.QuoteBlock(content: String, author: String, organisation: String)`. - `Block.ListBlock`, `Block.QuestionBlock`, `Block.AnswerBlock`. - `publication`: `Publication(publicationDate = ...)` - `url`: canonical web URL (`String`). - **Where the Article is created:** - `nl.persgroep.edition.article.data.converters.ArticleDtoMapper.invoke(ArticleDto): Article`. - In `ArticleViewModel`: `getCurrentArticle(): Article?` returns this domain model. - **Current share flow:** - Floating bottom bar `ArticleBottomToolbar` / `ActionPill` renders action icons (`ToolbarViewData.ToolbarAction.Share`). - Handled by `ArticleToolbarDelegateImpl.onShareClicked(ToolbarState.ArticleToolbar)` which emits `ShareEvent.ViewData(shareTitle, shareMessage)`. - Handled in `MainActivity.handleIntentEvent(NavigationEvent.Intent.Share)` -> `getIntentNavigator$app().share(this, shareViewData)`. - *Crucial note:* `ToolbarState.ArticleToolbar` and `ShareEvent.ViewData` currently only contain the article title and URL; they do **not** carry the body blocks. The full article object lives in `ArticleDtoMapper` / `ArticleViewModel`. ### 2. Kubus Platform (De Gelderlander, De Stentor, Tubantia, ED, BD, etc.) Researched on De Gelderlander (`com.mecom.gelderlander.nl`) 9.21.1. - **Architecture:** Hybrid Fragment + Compose (`com.p000kubusapp.*`). R8 obfuscates app code into `defpackage`, but keeps network Moshi models in `com.kubus.module.network.model.*` unobfuscated. - **Network model:** `com.kubus.module.network.model.ArticleDetailResponse`: - `metadata`: `com.kubus.module.network.model.Metadata` (`title`, `author`, `url`, `publicationDate`, etc.). - `components`: `List<com.kubus.module.network.model.ArticleComponent>`: - `Paragraph(properties: Paragraph.Properties)`: `properties.getContent()` (HTML formatted string). - `Title(properties: Title.Properties)`. - `Intro(properties: Intro.Properties)`. - `SubHeader(properties: SubHeader.Properties)`. - `PictureComponent(properties: PictureComponent.Properties)`: `properties.getUrl()`, `properties.getCaption()`, `properties.getSource()`. - `Quote(properties: Quote.Properties)`: `properties.getContent()`, `properties.getAuthor()`. - `ListComponent`, `Question`, `Answer`. - **Presentation model & mapper:** - `r20.b()` maps `ArticleDetailResponse` to `j20(componentsList: List<i30>, metadata: y30, presentation: t40)`. - Component mapping happens in `g20.a(ArticleComponent): i30` and `g20.b(List<ArticleComponent>): List<i30>`. - **Current share flow:** - Top toolbar in `ArticlePagerFragment` -> navigation flow emits `n50.c(j20)` (`ShareArticle`). - Handled by `ArticlePagerFragment.V0(j20 articleDetail)` -> calls `ha2.h(Context, j20)`. - `ha2.h(Context, j20)` constructs `Intent.ACTION_SEND` with `title + "\n\n" + url` and calls `context.startActivity(Intent.createChooser(...))`. - *Crucial note:* `j20` passed to `ha2.h` has `j20.getMetadata()` and `j20.c()` (presentation components `List<i30>`), while `ArticleDetailResponse` has the original unobfuscated Moshi components. --- ## Markdown formatter design (`extensions/extension`) Create a shared formatter in Java (e.g. `nl.midasvo.extension.markdown.ArticleMarkdownFormatter`): 1. **HTML parser / sanitizer:** - Lightweight regex or char-scanner converting inline tags without external dependencies: - `<b>`, `<strong>` -> `**...**` - `<i>`, `<em>` -> `*...*` - `<a href="(url)">(text)</a>` -> `[(text)]((url))` - `<br>`, `<p>`, `</p>` -> newlines - HTML entity decoding (`&amp;` -> `&`, `&quot;` -> `"`, `&#39;` -> `'`, `&lt;` -> `<`, `&gt;` -> `>`, `&nbsp;` -> ` `). - Strip unsupported tags (`<span>`, `<div>`, etc.). 2. **Template structure:** ```markdown # {Title} > *{Intro}* *{Author} • {PublicationDate}* [Origineel artikel]({Url}) --- {Body blocks formatted in order} ``` 3. **Block formatting rules:** - `SubHeader`: `\n\n## {text}\n\n` - `Paragraph`: `\n\n{formattedText}\n\n` - `Quote`: `\n\n> "{quote}"\n> — *{author}*\n\n` - `Image`: `\n\n![{caption}]({imageUrl})\n*{caption} (Beeld: {credits})*\n\n` - `List`: bullet points `* {item}\n` - `Q&A`: `### {question}\n\n{answer}\n\n` --- ## UI / UX options to trigger the action Consider the following three options: ### Option A: Intercept the Share Action / Show Chooser (Recommended) - Instead of immediately sharing only the URL link when tapping the native share button: - If the Midas toggle is active, show an Android Chooser / BottomSheet dialog or directly enhance the share: 1. **"Kopieer als Markdown"**: puts the markdown string into `ClipboardManager` and displays a short Toast: *"Artikel gekopieerd als Markdown"*. 2. **"Deel als Markdown"**: launches `ACTION_SEND` with the full Markdown text in `EXTRA_TEXT`. 3. **"Deel link"**: launches the original `ACTION_SEND` with just title + URL. - Advantage: Zero UI layout modifications required, works identically on all phone screen sizes and orientations. ### Option B: Dedicated in-app button - **de Volkskrant:** Append a Copy action to `ToolbarViewState.Content`'s `actions` list in `createToolbarArticleContent`, or add a button above/below the article. - **De Gelderlander:** Replace the space where `ShareButtons` were removed (at the bottom of the article body) with a styled "Kopieer als Markdown" button, or add a menu item in the top bar. ### Option C: Long-press on Share button - Short tap = normal link share. - Long press = copy formatted Markdown to clipboard. --- ## Proposed implementation steps 1. **Extension module (`extensions/extension`):** - Implement `ArticleMarkdownFormatter`: unit-tested standalone conversion logic. - Implement `MidasArticleStore`: holds the latest active article data (or directly converts during hook). - Implement `MidasShareHelper`: handles clipboard copy (`ClipboardManager`) with Toast, and/or launches custom chooser. - Add `BooleanSetting COPY_ARTICLE_MARKDOWN = new BooleanSetting("copy_article_markdown", true)` to `MidasSettings.java`. 2. **DPG Edition patch (`volkskrant`):** - Cache `Article` when created in `ArticleDtoMapper.invoke(ArticleDto): Article` (or in `ArticleRepositoryImpl.fetchArticle`). - Hook `ArticleToolbarDelegateImpl.onShareClicked` or `MainActivity.handleIntentEvent(NavigationEvent.Intent.Share)`: pass the cached article to `MidasShareHelper`. 3. **Kubus patch (`gelderlander`):** - Cache article components when `ArticleDetailResponse` is mapped, or hook `ha2.h(Context, j20)`: - In `ha2.h`: inspect `j20`, extract content (or retrieve cached Moshi components), and delegate to `MidasShareHelper`. 4. **Midas Settings registration:** - Register toggle **Artikel als Markdown kopiëren/delen** (`copy_article_markdown`, category "Artikelen", default on). 5. **Documentation:** - Update `docs/apps/volkskrant.md` and `docs/apps/gelderlander.md` with findings and hook points. --- ## Definition of done - [ ] `.\gradlew.bat buildAndroid` passes. - [ ] `.\scripts\patch-install.ps1 -NoInstall` applies on both apps. - [ ] Device test (with user confirmation): copying/sharing produces clean Markdown with intact formatting and image URLs. - [ ] Midas Settings toggle enables/disables the feature. - [ ] Documented in `docs/apps/volkskrant.md` and `docs/apps/gelderlander.md`.
Author
Owner

Opgeleverd in #54 (gemerged naar dev, gaat mee in de volgende stable release).

  • Knop: een eigen "Kopiëren als Markdown"-icoon (copy + M↓, in de lijnstijl van de app) links van Delen in de artikeltoolbar van de Volkskrant en De Gelderlander. Eén tik kopieert het artikel op het scherm; de deelknop is weer origineel. Toggle: Midas Settings → "Markdown-knop in artikelen".
  • Inhoud: titel, intro, auteur/datum, link naar het origineel, openingsfoto, tekst, tussenkoppen, foto's met bijschrift en fotograaf, citaten, lijsten.
  • Video's: als poster met link naar de video (en duur) wanneer de video-SDK de metadata al geladen heeft, anders een link naar het artikel.
  • Getest op de telefoon (Volkskrant 7.52.0, Gelderlander 9.21.1). Details in docs/apps/volkskrant.md en docs/apps/gelderlander.md.
Opgeleverd in #54 (gemerged naar dev, gaat mee in de volgende stable release). - **Knop**: een eigen "Kopiëren als Markdown"-icoon (copy + M↓, in de lijnstijl van de app) links van Delen in de artikeltoolbar van de Volkskrant en De Gelderlander. Eén tik kopieert het artikel op het scherm; de deelknop is weer origineel. Toggle: Midas Settings → "Markdown-knop in artikelen". - **Inhoud**: titel, intro, auteur/datum, link naar het origineel, openingsfoto, tekst, tussenkoppen, foto's met bijschrift en fotograaf, citaten, lijsten. - **Video's**: als poster met link naar de video (en duur) wanneer de video-SDK de metadata al geladen heeft, anders een link naar het artikel. - Getest op de telefoon (Volkskrant 7.52.0, Gelderlander 9.21.1). Details in docs/apps/volkskrant.md en docs/apps/gelderlander.md.
midas closed this issue 2026-10-10 18:19:47 +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#52
No description provided.