summaryrefslogtreecommitdiff
path: root/Pancake.hs
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-11-02 14:32:47 +0300
committerdefanor <defanor@uberspace.net>2017-11-02 14:32:47 +0300
commitef753eb1aa1c7370299ba7fa46652758c5adaab2 (patch)
tree5f4168d115ed789bb418b6bc4140c569d4a15ca6 /Pancake.hs
parent550805dfcbd026eca56bcc9e3000ef282015bedc (diff)
Shorten image reference texts
It is rather unpleasant to get long inline image URIs without titles.
Diffstat (limited to 'Pancake.hs')
-rw-r--r--Pancake.hs16
1 files changed, 14 insertions, 2 deletions
diff --git a/Pancake.hs b/Pancake.hs
index bc4812d..a9a972e 100644
--- a/Pancake.hs
+++ b/Pancake.hs
@@ -385,8 +385,20 @@ readInline (P.Link attr alt (url, title)) = do
pure $ (map $ Fg color) t ++
[Fg Blue $ fromString (concat ["[", show cnt, "]"])]
Nothing -> pure [fromString title]
-readInline (P.Image attr alt (url, title)) =
- (Fg Red "(image) " :) <$> readInline (P.Link attr alt (url, title))
+readInline (P.Image attr alt (url, title)) = do
+ storeAttr attr
+ (Fg Red "img:" :) <$> case parseURIReference url of
+ Nothing -> pure [fromString title]
+ Just uri -> do
+ a <- mapM readInline alt
+ let t = case (title, concat a) of
+ ("", []) -> [fromString $ takeFileName $ uriPath uri]
+ ("", alt') -> alt'
+ (title', []) -> [fromString title']
+ (_, alt') -> alt'
+ cnt <- storeLink uri
+ pure $ (map $ Fg Cyan) t ++
+ [Fg Blue $ fromString (concat ["[", show cnt, "]"])]
readInline (P.Note _) = pure . pure $ "(note: todo)"
readInline (P.Span attr i) = do
storeAttr attr