aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2022-08-03 09:43:51 +0200
committerAlbert Krewinkel <[email protected]>2022-08-03 09:51:13 +0200
commitb306f2e1fdf0cd340e49e3be91e267f456aefa0e (patch)
tree3eb6a56a36e6d3837ac5a84540d435f44d34d2bc /src
parent096863e0adf360b37334a3f8f81e704652b1706b (diff)
Org reader: add missing `/` to Windows file URI; fixes prev commit
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Org/Shared.hs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Shared.hs b/src/Text/Pandoc/Readers/Org/Shared.hs
index f3ef290da..f41644116 100644
--- a/src/Text/Pandoc/Readers/Org/Shared.hs
+++ b/src/Text/Pandoc/Readers/Org/Shared.hs
@@ -16,6 +16,7 @@ module Text.Pandoc.Readers.Org.Shared
, exportsCode
) where
+import Control.Applicative ((<|>))
import Data.Char (isAlphaNum)
import Data.Text (Text)
import qualified Data.Text as T
@@ -39,21 +40,21 @@ isImageFilename fp = hasImageExtension && (isValid (T.unpack fp) || isKnownProto
-- the string does not appear to be a link.
cleanLinkText :: Text -> Maybe Text
cleanLinkText s
- | isAbsolute s = Just $ "file://" <> s -- absolute path
+ | Just f <- toFileSchema s = Just f -- absolute path
| Just _ <- T.stripPrefix "./" s = Just s -- relative path
| Just _ <- T.stripPrefix "../" s = Just s -- relative path
-- Relative path or URL (file schema)
- | Just s' <- T.stripPrefix "file:" s = Just $
- if "//" `T.isPrefixOf` s'
- then s
- else if isAbsolute s'
- then "file://" <> s'
- else s'
+ | Just s' <- T.stripPrefix "file:" s = if "//" `T.isPrefixOf` s'
+ then Just s
+ else toFileSchema s' <|> Just s'
| isUrl s = Just s
| otherwise = Nothing
where
- isAbsolute :: Text -> Bool
- isAbsolute = ((||) <$> Posix.isAbsolute <*> Windows.isAbsolute) . T.unpack
+ toFileSchema :: Text -> Maybe Text
+ toFileSchema t
+ | Windows.isAbsolute (T.unpack t) = Just ("file:///" <> t)
+ | Posix.isAbsolute (T.unpack t) = Just ("file://" <> t)
+ | otherwise = Nothing
isUrl :: Text -> Bool
isUrl cs =
let (scheme, path) = T.break (== ':') cs