diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2020-03-30 22:03:52 +0200 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2020-03-30 22:03:52 +0200 |
commit | 69a3fa57087f54df6fe24c447cfbad8563befd36 (patch) | |
tree | bb2a183bdb72b44b24bec22f9bf5d973d75b8e70 | |
parent | 0069773364b8fad9b5c23752d0eac7ef7c1d0f1d (diff) | |
download | pandoc-69a3fa57087f54df6fe24c447cfbad8563befd36.tar.gz |
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.
-rw-r--r-- | src/Text/Pandoc/Readers/Jira.hs | 14 | ||||
-rw-r--r-- | test/Tests/Readers/Jira.hs | 9 |
2 files changed, 22 insertions, 1 deletions
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" |