mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-26 18:26:36 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user