From a2bbaa8367700ba71e53a958fd3b5fffd4b665f9 Mon Sep 17 00:00:00 2001 From: Rens Date: Wed, 9 Sep 2026 19:48:54 +0200 Subject: [PATCH] Strip paragraph attributes inside fenced divs during GFM export --- src/block.rs | 4 ++-- tests/test_export.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/block.rs b/src/block.rs index 91e44bb..c63726a 100644 --- a/src/block.rs +++ b/src/block.rs @@ -235,13 +235,13 @@ impl Trace { } /// Top-level block spans in source order; `nested` also includes - /// headings, tables, panels, and panel contents inside containers, in DFS order. + /// paragraphs, headings, tables, panels, and panel contents inside containers, in DFS order. pub(crate) fn into_spans(self, nested: bool) -> Vec { self.events .into_iter() .filter_map(|e| match e { Event::Block { span, depth } - if depth == 0 || (nested && (span.panel_body || matches!(span.kind, "heading" | "table" | "panel" | "panel_title"))) => + if depth == 0 || (nested && (span.panel_body || matches!(span.kind, "paragraph" | "heading" | "table" | "panel" | "panel_title"))) => { Some(*span) } diff --git a/tests/test_export.py b/tests/test_export.py index 8d86ee2..a485627 100644 --- a/tests/test_export.py +++ b/tests/test_export.py @@ -431,6 +431,17 @@ def test_md2gfm_nested_containers(): assert smp.count('{#sec-payment}') == 1 # real heading stripped; fenced example untouched +def test_md2gfm_paragraph_attributes_in_div(): + text = 'Aug 25, 2022 ยท Jeremy Howard' + example = '```markdown\n{: .literal}\n```' + source = f'::: {{.listing-card}}\n{text}\n{{: .listing-meta}}\n\n{example}\n:::\n' + html = md2mdhtml(source) + assert '

' in html and text in html + out = md2gfm(source) + assert text in out and example in out + assert 'listing-meta' not in out and 'listing-card' not in out and ':::' not in out + + def test_md2gfm_captions_and_figures(): md = ('| A |\n|---|\n| 1 |\n: Stages {#tbl-s}\n\n![A diagram](d.png){#fig-d}\n\n' 'See [@tbl-s] and [-@fig-d].')