aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/Jira.hs16
-rw-r--r--src/Text/Pandoc/Writers/Jira.hs28
2 files changed, 40 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/Jira.hs b/src/Text/Pandoc/Readers/Jira.hs
index d6fa688e3..46723f944 100644
--- a/src/Text/Pandoc/Readers/Jira.hs
+++ b/src/Text/Pandoc/Readers/Jira.hs
@@ -119,13 +119,14 @@ jiraToPandocInlines :: Jira.Inline -> Inlines
jiraToPandocInlines = \case
Jira.Anchor t -> spanWith (t, [], []) mempty
Jira.AutoLink url -> link (Jira.fromURL url) "" (str (Jira.fromURL url))
+ Jira.Citation ils -> str "—" <> space <> emph (fromInlines ils)
Jira.ColorInline c ils -> spanWith ("", [], [("color", colorName c)]) $
fromInlines ils
Jira.Emoji icon -> str . iconUnicode $ icon
Jira.Entity entity -> str . fromEntity $ entity
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.Link lt alias url -> jiraLinkToPandoc lt alias url
Jira.Linebreak -> linebreak
Jira.Monospaced inlns -> code . stringify . toList . fromInlines $ inlns
Jira.Space -> space
@@ -157,6 +158,19 @@ jiraToPandocInlines = \case
_ -> let kv = (Jira.parameterKey p, Jira.parameterValue p)
in (title, (ident, classes, kv:kvs))
+-- | Convert a Jira link to pandoc inlines.
+jiraLinkToPandoc :: Jira.LinkType -> [Jira.Inline] -> Jira.URL -> Inlines
+jiraLinkToPandoc linkType alias url =
+ let url' = (if linkType == Jira.User then ("~" <>) else id) $ Jira.fromURL url
+ alias' = case alias of
+ [] -> str url'
+ _ -> foldMap jiraToPandocInlines alias
+ in case linkType of
+ Jira.External -> link url' "" alias'
+ Jira.Email -> link ("mailto:" <> url') "" alias'
+ Jira.Attachment -> linkWith ("", ["attachment"], []) url' "" alias'
+ Jira.User -> linkWith ("", ["user-account"], []) url' "" alias'
+
-- | Get unicode representation of a Jira icon.
iconUnicode :: Jira.Icon -> Text
iconUnicode = \case
diff --git a/src/Text/Pandoc/Writers/Jira.hs b/src/Text/Pandoc/Writers/Jira.hs
index d1a656687..19db34137 100644
--- a/src/Text/Pandoc/Writers/Jira.hs
+++ b/src/Text/Pandoc/Writers/Jira.hs
@@ -1,5 +1,6 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE PatternGuards #-}
{- |
Module : Text.Pandoc.Writers.Jira
Copyright : © 2010-2020 Albert Krewinkel, John MacFarlane
@@ -25,7 +26,7 @@ import Text.Pandoc.Class.PandocMonad (PandocMonad)
import Text.Pandoc.Definition
import Text.Pandoc.Options (WriterOptions (writerTemplate, writerWrapText),
WrapOption (..))
-import Text.Pandoc.Shared (linesToPara)
+import Text.Pandoc.Shared (linesToPara, stringify)
import Text.Pandoc.Templates (renderTemplate)
import Text.Pandoc.Writers.Math (texMathToInlines)
import Text.Pandoc.Writers.Shared (defField, metaToContext)
@@ -193,8 +194,7 @@ toJiraInlines inlines = do
Emph xs -> styled Jira.Emphasis xs
Image attr _ tgt -> imageToJira attr (fst tgt) (snd tgt)
LineBreak -> pure . singleton $ Jira.Linebreak
- Link _ xs (tgt, _) -> singleton . flip Jira.Link (Jira.URL tgt)
- <$> toJiraInlines xs
+ Link attr xs tgt -> toJiraLink attr tgt xs
Math mtype cs -> mathToJira mtype cs
Note bs -> registerNotes bs
Quoted qt xs -> quotedToJira qt xs
@@ -242,6 +242,28 @@ imageToJira (_, classes, kvs) src title =
else Jira.Parameter "title" title : imgParams
in pure . singleton $ Jira.Image imgParams' (Jira.URL src)
+-- | Creates a Jira Link element.
+toJiraLink :: PandocMonad m
+ => Attr
+ -> Target
+ -> [Inline]
+ -> JiraConverter m [Jira.Inline]
+toJiraLink (_, classes, _) (url, _) alias = do
+ let (linkType, url') = toLinkType url
+ description <- if url `elem` [stringify alias, "mailto:" <> stringify alias]
+ then pure mempty
+ else toJiraInlines alias
+ pure . singleton $ Jira.Link linkType description (Jira.URL url')
+ where
+ toLinkType url'
+ | Just email <- T.stripPrefix "mailto:" url' = (Jira.Email, email)
+ | "user-account" `elem` classes = (Jira.User, dropTilde url)
+ | "attachment" `elem` classes = (Jira.Attachment, url)
+ | otherwise = (Jira.External, url)
+ dropTilde txt = case T.uncons txt of
+ Just ('~', username) -> username
+ _ -> txt
+
mathToJira :: PandocMonad m
=> MathType
-> Text