diff options
| author | John MacFarlane <[email protected]> | 2024-09-03 11:01:48 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-09-03 11:01:48 -0700 |
| commit | f048d8110e672148619094642f411d7ea223a17f (patch) | |
| tree | 6727ff7f175267ff525bed040f765ff79a36e8c6 /src | |
| parent | 6808788b21a0d71ed81634209c1183a13193f0ad (diff) | |
Text.Pandoc.Format: change formatFromFilePaths...
so that it is smarter about URLs. URLs are parsed, and we take the
format from the path component, if present.
This means that `https://emacs.org/` will be treated as HTML, while
`https://emacs.org/sample.org` will be treated as Org.
Closes #10141.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/App.hs | 2 | ||||
| -rw-r--r-- | src/Text/Pandoc/Format.hs | 8 |
2 files changed, 7 insertions, 3 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs index 4ae62f401..cdfcf7bbe 100644 --- a/src/Text/Pandoc/App.hs +++ b/src/Text/Pandoc/App.hs @@ -67,7 +67,6 @@ import Text.Pandoc.PDF (makePDF) import Text.Pandoc.Scripting (ScriptingEngine (..), CustomComponents(..)) import Text.Pandoc.SelfContained (makeSelfContained) import Text.Pandoc.Shared (tshow) -import Text.Pandoc.URI (isURI) import Text.Pandoc.Writers.Shared (lookupMetaString) import Text.Pandoc.Readers.Markdown (yamlToMeta) import qualified Text.Pandoc.UTF8 as UTF8 @@ -150,7 +149,6 @@ convertWithOpts' scriptingEngine istty datadir opts = do Nothing -> case Format.formatFromFilePaths sources of Just f' -> return f' Nothing | sources == ["-"] -> return $ defFlavor "markdown" - | any (isURI . T.pack) sources -> return $ defFlavor "html" | otherwise -> do report $ CouldNotDeduceFormat (map (T.pack . takeExtension) sources) "markdown" diff --git a/src/Text/Pandoc/Format.hs b/src/Text/Pandoc/Format.hs index 1f0f86988..3e1f3da88 100644 --- a/src/Text/Pandoc/Format.hs +++ b/src/Text/Pandoc/Format.hs @@ -38,6 +38,7 @@ import Text.Pandoc.Extensions , showExtension , readExtension ) +import Network.URI (URI (..), parseURI) import Text.Pandoc.Parsing import qualified Data.Text as T @@ -170,7 +171,7 @@ formatFromFilePaths = asum . map formatFromFilePath -- | Determines format based on file extension. formatFromFilePath :: FilePath -> Maybe FlavoredFormat formatFromFilePath x = - case takeExtension (map toLower x) of + case takeExtension (map toLower fpath) of ".Rmd" -> defFlavor "markdown" ".adoc" -> defFlavor "asciidoc" ".asciidoc" -> defFlavor "asciidoc" @@ -233,3 +234,8 @@ formatFromFilePath x = withExtension Nothing _ = Nothing withExtension (Just (FlavoredFormat f ed)) ext = Just $ FlavoredFormat f (ed <> ExtensionsDiff (extensionsFromList [ext]) mempty) + fpath = case parseURI x of + Nothing -> x + Just URI{ uriPath = "" } -> "index.html" + Just URI{ uriPath = "/" } -> "index.html" + Just URI{ uriPath = up } -> up |
