From 69a3fa57087f54df6fe24c447cfbad8563befd36 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Mon, 30 Mar 2020 22:03:52 +0200 Subject: Jira reader: retain image attributes Jira images attributes as in `!image.jpg|align=right!` are retained as key-value pairs. Thumbnail images, such as `!example.gif|thumbnail!`, are marked by a `thumbnail` class in their attributes. Related to #6234. --- src/Text/Pandoc/Readers/Jira.hs | 14 +++++++++++++- test/Tests/Readers/Jira.hs | 9 +++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Text/Pandoc/Readers/Jira.hs b/src/Text/Pandoc/Readers/Jira.hs index 117239d40..cfe8ba81c 100644 --- a/src/Text/Pandoc/Readers/Jira.hs +++ b/src/Text/Pandoc/Readers/Jira.hs @@ -123,7 +123,8 @@ jiraToPandocInlines = \case fromInlines ils Jira.Emoji icon -> str . iconUnicode $ icon Jira.Entity entity -> str . fromEntity $ entity - Jira.Image _ url -> image (Jira.fromURL url) "" mempty + Jira.Image params url -> let (title, attr) = imgParams params + in imageWith attr (Jira.fromURL url) title mempty Jira.Link alias url -> link (Jira.fromURL url) "" (fromInlines alias) Jira.Linebreak -> linebreak Jira.Monospaced inlns -> code . stringify . toList . fromInlines $ inlns @@ -145,6 +146,17 @@ jiraToPandocInlines = \case Jira.Subscript -> subscript Jira.Superscript -> superscript + imgParams :: [Jira.Parameter] -> (Text, Attr) + imgParams = foldr addImgParam ("", ("", [], [])) + + addImgParam :: Jira.Parameter -> (Text, Attr) -> (Text, Attr) + addImgParam p (title, attr@(ident, classes, kvs)) = + case Jira.parameterKey p of + "title" -> (Jira.parameterValue p, attr) + "thumbnail" -> (title, (ident, "thumbnail":classes, kvs)) + _ -> let kv = (Jira.parameterKey p, Jira.parameterValue p) + in (title, (ident, classes, kv:kvs)) + -- | Get unicode representation of a Jira icon. iconUnicode :: Jira.Icon -> Text iconUnicode = \case diff --git a/test/Tests/Readers/Jira.hs b/test/Tests/Readers/Jira.hs index 299db7bed..1ae3244ab 100644 --- a/test/Tests/Readers/Jira.hs +++ b/test/Tests/Readers/Jira.hs @@ -117,6 +117,15 @@ tests = "!https://example.com/image.jpg!" =?> para (image "https://example.com/image.jpg" "" mempty) + , "thumbnail image" =: + "!image.jpg|thumbnail!" =?> + para (imageWith ("", ["thumbnail"], []) "image.jpg" "" mempty) + + , "image with attributes" =: + "!image.gif|align=right, vspace=4, title=Hello!" =?> + let attr = ("", [], [("align", "right"), ("vspace", "4")]) + in para $ imageWith attr "image.gif" "Hello" mempty + , "HTML entity" =: "me & you" =?> para "me & you" -- cgit v1.2.3