aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorAlbert Krewinkel <tarleb@moltkeplatz.de>2014-04-05 16:10:52 +0200
committerAlbert Krewinkel <tarleb@moltkeplatz.de>2014-04-05 16:15:53 +0200
commit652c781e375f3678a0ec821663240d4958f324de (patch)
tree8cf9516bbe206b8be0300272a2dad7518e271a74 /src/Text
parentd76d2b707b2b5cebb38122e117527a70996c2c4f (diff)
downloadpandoc-652c781e375f3678a0ec821663240d4958f324de.tar.gz
Org reader: Support inline images
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Org.hs34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/Org.hs b/src/Text/Pandoc/Readers/Org.hs
index 62088a04d..8b1b4fa23 100644
--- a/src/Text/Pandoc/Readers/Org.hs
+++ b/src/Text/Pandoc/Readers/Org.hs
@@ -39,7 +39,7 @@ import Control.Applicative (pure, (<$>), (<$), (<*>), (<*), (*>), (<**
import Control.Monad (guard, mzero)
import Data.Char (toLower)
import Data.Default
-import Data.List (foldl')
+import Data.List (foldl', isPrefixOf, isSuffixOf)
import Data.Maybe (listToMaybe, fromMaybe)
import Data.Monoid (mconcat, mempty, mappend)
@@ -484,20 +484,26 @@ endline = try $ do
return B.space
link :: OrgParser Inlines
-link = explicitLink <|> selfLink <?> "link"
+link = explicitOrImageLink <|> selflinkOrImage <?> "link"
-explicitLink :: OrgParser Inlines
-explicitLink = try $ do
+explicitOrImageLink :: OrgParser Inlines
+explicitOrImageLink = try $ do
char '['
- src <- enclosedRaw (char '[') (char ']')
- title <- enclosedInlines (char '[') (char ']')
+ src <- enclosedRaw (char '[') (char ']')
+ title <- enclosedRaw (char '[') (char ']')
+ title' <- parseFromString (mconcat . butLast <$> many inline) (title++"\n")
char ']'
- return $ B.link src "" title
+ return $ if (isImage src) && (isImage title)
+ then B.link src "" (B.image title "" "")
+ else B.link src "" title'
+ where butLast = reverse . tail . reverse
-selfLink :: OrgParser Inlines
-selfLink = try $ do
+selflinkOrImage :: OrgParser Inlines
+selflinkOrImage = try $ do
src <- enclosedRaw (string "[[") (string "]]")
- return $ B.link src "" (B.str src)
+ return $ if isImage src
+ then B.image src "" ""
+ else B.link src "" (B.str src)
emph :: OrgParser Inlines
emph = B.emph <$> inlinesEnclosedBy '/'
@@ -606,3 +612,11 @@ endsOnThisLine input c doOnOtherLines = do
then return ()
else endsOnThisLine rest c doOnOtherLines
_ -> mzero
+
+isImage filename =
+ any (\x -> ('.':x) `isSuffixOf` filename) imageExtensions &&
+ any (\x -> (x++":") `isPrefixOf` filename) protocols ||
+ ':' `notElem` filename
+ where
+ imageExtensions = [ "jpeg" , "jpg" , "png" , "gif" , "svg" ]
+ protocols = [ "file", "http", "https" ]