From b306f2e1fdf0cd340e49e3be91e267f456aefa0e Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Wed, 3 Aug 2022 09:43:51 +0200 Subject: Org reader: add missing `/` to Windows file URI; fixes prev commit --- src/Text/Pandoc/Readers/Org/Shared.hs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src') 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 -- cgit v1.2.3