Skip to content

Commit 4ae637c

Browse files
committed
Revert "Better normalization of filepaths"
This reverts commit c5009bd.
1 parent 7fb8096 commit 4ae637c

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

src/Text/Pandoc/Filter/Plot/Parse.hs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ import Data.Version (showVersion)
3333

3434
import Paths_pandoc_plot (version)
3535

36-
import System.FilePath (makeValid)
37-
import System.Directory (canonicalizePath)
36+
import System.FilePath (makeValid, normalise)
3837

3938
import Text.Pandoc.Definition (Block (..), Inline,
4039
Pandoc (..), Format(..))
@@ -90,8 +89,8 @@ parseFigureSpec block@(CodeBlock (id', classes, attrs) _) =
9089
extraAttrs = Map.toList extraAttrs'
9190
blockAttrs = (id', filter (/= cls toolkit) classes, filteredAttrs)
9291

93-
blockDependencies <- parseFileDependencies $ fromMaybe mempty $ Map.lookup (tshow DependenciesK) attrs'
94-
let dependencies = (defaultDependencies conf) <> blockDependencies
92+
let blockDependencies = parseFileDependencies $ fromMaybe mempty $ Map.lookup (tshow DependenciesK) attrs'
93+
dependencies = (defaultDependencies conf) <> blockDependencies
9594

9695
-- This is the first opportunity to check save format compatibility
9796
let saveFormatSupported = saveFormat `elem` (supportedSaveFormats toolkit)
@@ -110,7 +109,7 @@ parseFigureSpec _ = return Nothing
110109
parseContent :: Block -> PlotM Script
111110
parseContent (CodeBlock (_, _, attrs) content) = do
112111
let attrs' = Map.fromList attrs
113-
mfile <- liftIO $ sequence $ fmap canonicalizePath $ unpack <$> Map.lookup (tshow FileK) attrs'
112+
mfile = unpack <$> Map.lookup (tshow FileK) attrs'
114113
when (content /= mempty && isJust mfile) $ do
115114
err $ mconcat [
116115
"Figure refers to a file (", pack $ fromJust mfile
@@ -157,10 +156,11 @@ readBool s | s `elem` ["True", "true", "'True'", "'true'", "1"] = True
157156

158157

159158
-- | Parse a list of file dependencies such as /[foo.bar, hello.txt]/.
160-
parseFileDependencies :: Text -> PlotM [FilePath]
159+
parseFileDependencies :: Text -> [FilePath]
161160
parseFileDependencies t
162-
| t == mempty = return mempty
163-
| otherwise = sequence $
164-
fmap (liftIO . canonicalizePath . unpack . T.dropAround isSpace)
165-
. T.splitOn ","
166-
. T.dropAround (\c -> c `elem` ['[', ']']) $ t
161+
| t == mempty = mempty
162+
| otherwise = fmap normalise
163+
. fmap unpack
164+
. fmap (T.dropAround isSpace) -- Remove leading/trailing whitespace on filenames
165+
. T.splitOn ","
166+
. T.dropAround (\c -> c `elem` ['[', ']']) $ t

src/Text/Pandoc/Filter/Plot/Renderers/Prelude.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Text.Pandoc.Filter.Plot.Renderers.Prelude (
2525
import Data.Maybe (isJust)
2626
import Data.Text (Text, unpack)
2727

28-
import System.Directory (findExecutable, canonicalizePath)
28+
import System.Directory (findExecutable)
2929
import System.Exit (ExitCode(..))
3030

3131
import Text.Shakespeare.Text (st)
@@ -43,9 +43,7 @@ commandSuccess s = do
4343

4444
-- | Checks that an executable is available on path, at all.
4545
existsOnPath :: FilePath -> IO Bool
46-
existsOnPath fp = canonicalizePath fp
47-
>>= findExecutable
48-
>>= fmap isJust . return
46+
existsOnPath fp = findExecutable fp >>= fmap isJust . return
4947

5048

5149
-- | Try to find the executable and normalise its path.

src/Text/Pandoc/Filter/Plot/Scripting.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import qualified Data.Text.IO as T
2727
import Paths_pandoc_plot (version)
2828

2929
import System.Directory (createDirectoryIfMissing,
30-
doesFileExist, getTemporaryDirectory,
31-
canonicalizePath)
30+
doesFileExist, getTemporaryDirectory)
3231
import System.Exit (ExitCode (..))
33-
import System.FilePath (addExtension, replaceExtension,
32+
import System.FilePath (addExtension,
33+
normalise, replaceExtension,
3434
takeDirectory, (</>))
3535

3636
import Text.Pandoc.Filter.Plot.Renderers
@@ -131,7 +131,7 @@ tempScriptPath FigureSpec{..} = do
131131

132132
-- | Determine the path to the source code that generated the figure.
133133
sourceCodePath :: FigureSpec -> PlotM FilePath
134-
sourceCodePath = fmap (flip replaceExtension ".txt") . figurePath
134+
sourceCodePath = fmap normalise . fmap (flip replaceExtension ".txt") . figurePath
135135

136136

137137
-- | Hash of the content of a @FigureSpec@. Note that unlike usual hashes,
@@ -165,4 +165,4 @@ figurePath spec = do
165165
fh <- figureContentHash spec
166166
let ext = extension . saveFormat $ spec
167167
stem = flip addExtension ext . show $ fh
168-
liftIO $ canonicalizePath $ directory spec </> stem
168+
return $ normalise $ directory spec </> stem

0 commit comments

Comments
 (0)