Skip to content

Commit

Permalink
commonmark-pandoc: add wrapper="1" when we need to add Div or Span.
Browse files Browse the repository at this point in the history
This is needed for good round-tripping; a djot writer can see
that this attribute was added and remove the wrapping, adding
the attributes directly to the element.
  • Loading branch information
jgm committed Sep 13, 2024
1 parent ff9fe57 commit 7130ce2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions commonmark-pandoc/src/Commonmark/Pandoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ addBlockAttrs attrs (Table curattrs capt colspecs thead tbody tfoot) =
Table (addToPandocAttr attrs curattrs) capt colspecs thead tbody tfoot
addBlockAttrs attrs (Div curattrs bs) =
Div (addToPandocAttr attrs curattrs) bs
addBlockAttrs attrs x =
Div (addToPandocAttr attrs nullAttr) [x]
addBlockAttrs attrs x = -- add wrapper="1" if we needed to add a Div
Div (addToPandocAttr (("wrapper","1"):attrs) nullAttr) [x]

addInlineAttrs :: [(T.Text, T.Text)] -> Inline -> Inline
addInlineAttrs attrs (Link curattrs ils target) =
Expand All @@ -218,8 +218,8 @@ addInlineAttrs attrs (Span curattrs ils) =
Span (addToPandocAttr attrs curattrs) ils
addInlineAttrs attrs (Code curattrs s) =
Code (addToPandocAttr attrs curattrs) s
addInlineAttrs attrs x =
Span (addToPandocAttr attrs nullAttr) [x]
addInlineAttrs attrs x = -- add wrapper="1" if we needed to add a Span
Span (addToPandocAttr (("wrapper","1"):attrs) nullAttr) [x]

addToPandocAttr :: Attributes -> Attr -> Attr
addToPandocAttr attrs attr = foldr go attr attrs
Expand Down

0 comments on commit 7130ce2

Please sign in to comment.