diff --git a/CHANGELOG.md b/CHANGELOG.md index a5dba406..1b336806 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.11.0] - 2022-01-25 +### Added +- Literate now tries to figure out the branch/commit that `EditURL` should point to + automatically instead of always defaulting to `"master"`. For typical setups the + auto-detection should be sufficient, but you can also set it explicitly by passing + `edit_commit`, for example `edit_commit = "main"`. ([#179][github-179], [#184][github-184]) + ## [2.10.0] - 2022-01-24 ### Added - Markdown execution now also support `image/svg+xml`. ([#182][github-182], [#183][github-183]) @@ -159,10 +166,14 @@ https://discourse.julialang.org/t/ann-literate-jl/10651 for release announcement [github-169]: https://github.com/fredrikekre/Literate.jl/pull/169 [github-171]: https://github.com/fredrikekre/Literate.jl/issues/171 [github-172]: https://github.com/fredrikekre/Literate.jl/pull/172 +[github-179]: https://github.com/fredrikekre/Literate.jl/issues/179 [github-182]: https://github.com/fredrikekre/Literate.jl/issues/182 [github-183]: https://github.com/fredrikekre/Literate.jl/pull/183 +[github-184]: https://github.com/fredrikekre/Literate.jl/pull/184 -[Unreleased]: https://github.com/fredrikekre/Literate.jl/compare/v2.9.4...HEAD +[Unreleased]: https://github.com/fredrikekre/Literate.jl/compare/v2.11.0...HEAD +[2.11.0]: https://github.com/fredrikekre/Literate.jl/compare/v2.10.0...v2.11.0 +[2.10.0]: https://github.com/fredrikekre/Literate.jl/compare/v2.9.4...v2.10.0 [2.9.4]: https://github.com/fredrikekre/Literate.jl/compare/v2.9.3...v2.9.4 [2.9.3]: https://github.com/fredrikekre/Literate.jl/compare/v2.9.2...v2.9.3 [2.9.2]: https://github.com/fredrikekre/Literate.jl/compare/v2.9.1...v2.9.2 diff --git a/Project.toml b/Project.toml index d91dded1..415453cf 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Literate" uuid = "98b081ad-f1c9-55d3-8b20-4c87d4299306" -version = "2.10.0" +version = "2.11.0" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" diff --git a/docs/Manifest.toml b/docs/Manifest.toml index 9e0aad0b..7971070a 100644 --- a/docs/Manifest.toml +++ b/docs/Manifest.toml @@ -388,7 +388,7 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" deps = ["Base64", "IOCapture", "JSON", "REPL"] path = ".." uuid = "98b081ad-f1c9-55d3-8b20-4c87d4299306" -version = "2.10.0" +version = "2.11.0" [[LogExpFunctions]] deps = ["ChainRulesCore", "ChangesOfVariables", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"] diff --git a/src/Literate.jl b/src/Literate.jl index 37350f15..76109aff 100644 --- a/src/Literate.jl +++ b/src/Literate.jl @@ -264,8 +264,21 @@ function create_configuration(inputfile; user_config, user_kwargs, type=nothing) ("````@example $(get(user_config, "name", replace(cfg["name"], r"\s" => "_")))" => "````") : ("````julia" => "````") cfg["image_formats"] = _DEFAULT_IMAGE_FORMATS - # Guess the package (or repository) root url - edit_commit = "master" # TODO: Make this configurable like Documenter? + # Guess the package (or repository) root url with "master" as fallback + # see JuliaDocs/Documenter.jl#1751 + fallback_edit_commit = "master" + if (git = Sys.which("git"); git !== nothing) + try + str = read(pipeline(ignorestatus( + setenv(`$(git) remote show origin`; dir=dirname(inputfile)) + ), stderr=devnull), String) + if (m = match(r"^\s*HEAD branch:\s*(.*)$"m, str); m !== nothing) + fallback_edit_commit = String(m[1]) + end + catch + end + end + cfg["edit_commit"] = get(user_config, "edit_commit", fallback_edit_commit) deploy_branch = "gh-pages" # TODO: Make this configurable like Documenter? # Strip build version from a tag (cf. JuliaDocs/Documenter.jl#1298, Literate.jl#162) function version_tag_strip_build(tag) @@ -288,7 +301,7 @@ function create_configuration(inputfile; user_config, user_kwargs, type=nothing) else "previews/PR$(get(ENV, "TRAVIS_PULL_REQUEST", "##"))" end - cfg["repo_root_url"] = "https://github.com/$(repo_slug)/blob/$(edit_commit)" + cfg["repo_root_url"] = "https://github.com/$(repo_slug)/blob/$(cfg["edit_commit"])" cfg["nbviewer_root_url"] = "https://nbviewer.jupyter.org/github/$(repo_slug)/blob/$(deploy_branch)/$(deploy_folder)" cfg["binder_root_url"] = "https://mybinder.org/v2/gh/$(repo_slug)/$(deploy_branch)?filepath=$(deploy_folder)" if (dir = get(ENV, "TRAVIS_BUILD_DIR", nothing)) !== nothing @@ -307,7 +320,7 @@ function create_configuration(inputfile; user_config, user_kwargs, type=nothing) else "dev" end - cfg["repo_root_url"] = "https://github.com/$(repo_slug)/blob/$(edit_commit)" + cfg["repo_root_url"] = "https://github.com/$(repo_slug)/blob/$(cfg["edit_commit"])" cfg["nbviewer_root_url"] = "https://nbviewer.jupyter.org/github/$(repo_slug)/blob/$(deploy_branch)/$(deploy_folder)" cfg["binder_root_url"] = "https://mybinder.org/v2/gh/$(repo_slug)/$(deploy_branch)?filepath=$(deploy_folder)" if (dir = get(ENV, "GITHUB_WORKSPACE", nothing)) !== nothing @@ -315,7 +328,7 @@ function create_configuration(inputfile; user_config, user_kwargs, type=nothing) end elseif haskey(ENV, "GITLAB_CI") if (url = get(ENV, "CI_PROJECT_URL", nothing)) !== nothing - cfg["repo_root_url"] = "$(url)/blob/$(edit_commit)" + cfg["repo_root_url"] = "$(url)/blob/$(cfg["edit_commit"])" end if (url = get(ENV, "CI_PAGES_URL", nothing)) !== nothing && (m = match(r"https://(.+)", url)) !== nothing diff --git a/test/runtests.jl b/test/runtests.jl index c229c7e6..9d344279 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -762,6 +762,14 @@ end end markdown = read(joinpath(outdir, "inputfile.md"), String) @test !occursin("md\"\"\"", markdown) + # edit_commit + withenv(ACTIONS_ENV...) do + Literate.markdown(inputfile, outdir; edit_commit="retsam") + end + markdown = read(joinpath(outdir, "inputfile.md"), String) + @test occursin("blob/retsam/", markdown) + @test !occursin("blob/master/", markdown) + # execute write(inputfile, """ using DisplayAs