From 60125b96f2d709011c455c96dbfd394888f1532c Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Tue, 23 Aug 2022 16:22:08 +1200 Subject: [PATCH] Normalize line endings in MD source before parsing (#1906) --- CHANGELOG.md | 4 ++++ src/Documents.jl | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8445a2e6a..97795b0757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ * ![Enhancement][badge-enhancement] The code copy buttons in HTML now have `title` and `aria-label` attributes. ([#1903][github-1903]) * ![Bugfix][badge-bugfix] Documenter now generates the correct source URLs for docstrings from other packages when the `repo` argument to `makedocs` is set (note: the source links to such docstrings only work if the external package is cloned from GitHub and added as a dev-dependency). However, this change **breaks** the case where the `repo` argument is used to override the main package/repository URL, assuming the repository is cloned from GitHub. ([#1808][github-1808]) * ![Bugfix][badge-bugfix] Documenter no longer uses the `TRAVIS_REPO_SLUG` environment variable to determine the Git remote of non-main repositories (when inferring it from the Git repository configuration has failed), which could previously lead to bad source links. ([#1881][github-1881]) +* ![Bugfix][badge-bugfix] Line endings in Markdown source files are now normalized to `LF` before parsing, to work around [a bug in the Julia Markdown parser][julia-29344] where parsing is sensitive to line endings, and can therefore cause platform-dependent behavior. ([#1906][github-1906]) ## Version `v0.27.22` @@ -1119,8 +1120,11 @@ [github-1886]: https://github.com/JuliaDocs/Documenter.jl/pull/1886 [github-1890]: https://github.com/JuliaDocs/Documenter.jl/pull/1890 [github-1903]: https://github.com/JuliaDocs/Documenter.jl/pull/1903 +[github-1906]: https://github.com/JuliaDocs/Documenter.jl/pull/1906 + +[julia-29344]: https://github.com/JuliaLang/julia/issues/29344 [julia-38079]: https://github.com/JuliaLang/julia/issues/38079 [julia-39841]: https://github.com/JuliaLang/julia/pull/39841 [julia-45174]: https://github.com/JuliaLang/julia/issues/45174 diff --git a/src/Documents.jl b/src/Documents.jl index a9a9b589f6..0be437829e 100644 --- a/src/Documents.jl +++ b/src/Documents.jl @@ -55,7 +55,14 @@ struct Page md2ast :: Markdown2.MD end function Page(source::AbstractString, build::AbstractString, workdir::AbstractString) - mdpage = Markdown.parse(read(source, String)) + # The Markdown standard library parser is sensitive to line endings: + # https://github.com/JuliaLang/julia/issues/29344 + # This can lead to different AST and therefore differently rendered docs, depending on + # what platform the docs are being built (e.g. when Git checks out LF files with + # CRFL line endings on Windows). To make sure that the docs are always built consistently, + # we'll normalize the line endings when parsing Markdown files by removing all CR characters. + mdsrc = replace(read(source, String), '\r' => "") + mdpage = Markdown.parse(mdsrc) md2ast = try Markdown2.convert(Markdown2.MD, mdpage) catch err