diff options
| author | Albert Krewinkel <[email protected]> | 2022-08-03 09:43:51 +0200 |
|---|---|---|
| committer | Albert Krewinkel <[email protected]> | 2022-08-03 09:51:13 +0200 |
| commit | b306f2e1fdf0cd340e49e3be91e267f456aefa0e (patch) | |
| tree | 3eb6a56a36e6d3837ac5a84540d435f44d34d2bc | |
| parent | 096863e0adf360b37334a3f8f81e704652b1706b (diff) | |
Org reader: add missing `/` to Windows file URI; fixes prev commit
| -rw-r--r-- | src/Text/Pandoc/Readers/Org/Shared.hs | 19 | ||||
| -rw-r--r-- | test/command/8201.md | 2 |
2 files changed, 11 insertions, 10 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 diff --git a/test/command/8201.md b/test/command/8201.md index 288270ab3..854e13d97 100644 --- a/test/command/8201.md +++ b/test/command/8201.md @@ -2,5 +2,5 @@ % pandoc -f org -t html [[file:d:/Home/Documents/test.png][Link Test]] ^D -<p><a href="file://d:/Home/Documents/test.png">Link Test</a></p> +<p><a href="file:///d:/Home/Documents/test.png">Link Test</a></p> ``` |
