[#164] Use only '/' as path separator

Problem: in markdown links, '/' should always be used as path separator ,
e.g. GitHub renderer is not threating link `[x](a\b.md)` as a link
to file in dir `a`
We use OS-dependent file separators everywhere, so
e.g. `canonizeLocalRef "./a.md"="./a.md`"` on Windows

Solution: replace '\' to '/' while constructing repo tree if needed
and then use only '/', preferring functions from `System.FilePath.Posix`.
We can do this, since 'a/b' and `a\b` are equivalent paths on Windows
This commit is contained in:
Anton Sorokin 2022-10-11 23:35:44 +03:00
parent 09783e0213
commit aba295b478
No known key found for this signature in database
GPG Key ID: 4B53B91ADFBFB649
7 changed files with 13 additions and 14 deletions

View File

@ -22,7 +22,7 @@ import Data.List qualified as L
import Data.Reflection (Given)
import Data.Text qualified as T
import Fmt (Buildable (..))
import System.FilePath (isPathSeparator, pathSeparator)
import System.FilePath.Posix (isPathSeparator)
import Text.Interpolation.Nyan
import Time (Second, Time)
@ -339,7 +339,7 @@ canonizeLocalRef :: Text -> Text
canonizeLocalRef ref =
maybe ref canonizeLocalRef (T.stripPrefix localPrefix ref)
where
localPrefix = toText ['.', pathSeparator]
localPrefix = "./"
-----------------------------------------------------------
-- Visualisation

View File

@ -38,7 +38,7 @@ import Data.Map qualified as M
import Data.Reflection (Given)
import Fmt (Buildable (..), fmt)
import System.Directory (doesDirectoryExist)
import System.FilePath
import System.FilePath.Posix
(dropTrailingPathSeparator, equalFilePath, splitDirectories, takeDirectory, takeExtension, (</>))
import System.Process (cwd, readCreateProcess, shell)
import Text.Interpolation.Nyan

View File

@ -21,10 +21,9 @@ import Data.Coerce (coerce)
import GHC.IO.Unsafe (unsafePerformIO)
import System.Directory (canonicalizePath)
import System.Environment (lookupEnv)
import System.FilePath (isRelative, (</>))
import System.FilePath.Glob (CompOptions (errorRecovery))
import System.FilePath.Glob qualified as Glob
import Text.Interpolation.Nyan
import System.FilePath.Posix (isRelative, (</>))
import Xrefcheck.Util (normaliseWithNoTrailing)
@ -89,4 +88,4 @@ instance FromJSON RelGlobPattern where
-- | Glob compilation options we use.
globCompileOptions :: Glob.CompOptions
globCompileOptions = Glob.compDefault{errorRecovery = False}
globCompileOptions = Glob.compDefault{Glob.errorRecovery = False}

View File

@ -27,7 +27,7 @@ import Data.Time (UTCTime)
import Data.Time.Clock (nominalDiffTimeToSeconds)
import Data.Time.Clock.POSIX (POSIXTime, utcTimeToPOSIXSeconds)
import Fmt (Builder)
import System.FilePath (dropTrailingPathSeparator, normalise)
import System.FilePath.Posix (dropTrailingPathSeparator, normalise)
import Time (Second, Time (..), sec)
import Xrefcheck.Util.Colorize

View File

@ -56,7 +56,7 @@ import Network.HTTP.Req
HttpMethod, NoReqBody (..), defaultHttpConfig, ignoreResponse, req, runReq, useURI)
import Network.HTTP.Types.Header (hRetryAfter)
import Network.HTTP.Types.Status (Status, statusCode, statusMessage)
import System.FilePath
import System.FilePath.Posix
(equalFilePath, joinPath, makeRelative, normalise, splitDirectories, takeDirectory, (</>))
import Text.Interpolation.Nyan
import Text.ParserCombinators.ReadPrec qualified as ReadPrec (lift)

View File

@ -13,7 +13,7 @@ extra-deps:
- firefly-0.2.1.0@sha256:e9d73486464c3e223ec457e02b30ddd5b550fdbf6292b268c64581e2b07d888b,1519
- cmark-gfm-0.2.5
- git: https://github.com/serokell/nyan-interpolation
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
subdirs:
- full
- core

View File

@ -19,7 +19,7 @@ packages:
original:
hackage: cmark-gfm-0.2.5
- completed:
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
git: https://github.com/serokell/nyan-interpolation
name: nyan-interpolation
pantry-tree:
@ -28,20 +28,20 @@ packages:
subdir: full
version: '0.9'
original:
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
git: https://github.com/serokell/nyan-interpolation
subdir: full
- completed:
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
git: https://github.com/serokell/nyan-interpolation
name: nyan-interpolation-core
pantry-tree:
sha256: 59d1c732629b06d0035229dccce484d6b4c3078d6bb3e493317afddc9be233df
sha256: 4802161ce5d38f895e3b5106c789bfbe20b8d12c2f6c5fcba3999bec105283bc
size: 1516
subdir: core
version: '0.9'
original:
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
git: https://github.com/serokell/nyan-interpolation
subdir: core
snapshots: