Browse Source

Remove at-extref from non-Documenter output (#245)

pull/246/head
nathan musoke 2 years ago committed by GitHub
parent
commit
142bbeefa5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      CHANGELOG.md
  2. 8
      docs/src/documenter.md
  3. 4
      src/Literate.jl
  4. 6
      test/runtests.jl

10
CHANGELOG.md

@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- Literate will now remove Documenter-style `@extref` links under the same
circumstances as `@ref` and `@id`. Recent versions of Documenter use
`@extref` to links to the documentation of external packages. See
https://github.com/JuliaDocs/Documenter.jl/issues/2366 for details of
the Documenter implementation. ([#245])
## [v2.17.0] - 2024-04-14 ## [v2.17.0] - 2024-04-14
### Added ### Added
- Literate can now output [Quarto](https://quarto.org/) notebooks (markdown documents with - Literate can now output [Quarto](https://quarto.org/) notebooks (markdown documents with
@ -303,6 +312,7 @@ https://discourse.julialang.org/t/ann-literate-jl/10651 for release announcement
[#229]: https://github.com/fredrikekre/Literate.jl/issues/229 [#229]: https://github.com/fredrikekre/Literate.jl/issues/229
[#230]: https://github.com/fredrikekre/Literate.jl/issues/230 [#230]: https://github.com/fredrikekre/Literate.jl/issues/230
[#233]: https://github.com/fredrikekre/Literate.jl/issues/233 [#233]: https://github.com/fredrikekre/Literate.jl/issues/233
[#245]: https://github.com/fredrikekre/Literate.jl/issues/245
[0872a96]: https://github.com/fredrikekre/Literate.jl/commit/0872a96 [0872a96]: https://github.com/fredrikekre/Literate.jl/commit/0872a96
[0f9e836]: https://github.com/fredrikekre/Literate.jl/commit/0f9e836 [0f9e836]: https://github.com/fredrikekre/Literate.jl/commit/0f9e836
[1d02868]: https://github.com/fredrikekre/Literate.jl/commit/1d02868 [1d02868]: https://github.com/fredrikekre/Literate.jl/commit/1d02868

8
docs/src/documenter.md

@ -31,8 +31,8 @@ if we set `documenter = true`:
```` ````
### [`Literate.notebook`](@ref): ### [`Literate.notebook`](@ref):
- Documenter style `@ref`s and `@id` will be removed. This means that you can use - Documenter style `@ref`s, `@extref`s and `@id` will be removed. This means that you can use
`@ref` and `@id` in the source file without them leaking to the notebook. `@ref`, `@extref` and `@id` in the source file without them leaking to the notebook.
- Documenter style markdown math - Documenter style markdown math
```` ````
```math ```math
@ -57,5 +57,5 @@ if we set `documenter = true`:
``` ```
### [`Literate.script`](@ref): ### [`Literate.script`](@ref):
- Documenter style `@ref`s and `@id` will be removed. This means that you can use - Documenter style `@ref`s, `@extref`s and `@id` will be removed. This means that you can use
`@ref` and `@id` in the source file without them leaking to the script. `@ref`, `@extref` and `@id` in the source file without them leaking to the script.

4
src/Literate.jl

@ -217,9 +217,11 @@ function replace_default(content, sym;
# Run some Documenter specific things # Run some Documenter specific things
if !isdocumenter(config) if !isdocumenter(config)
## - remove documenter style `@ref`s and `@id`s ## - remove documenter style `@ref`s, `@extref`s and `@id`s
push!(repls, r"\[([^]]+?)\]\(@ref\)"s => s"\1") # [foo](@ref) => foo push!(repls, r"\[([^]]+?)\]\(@ref\)"s => s"\1") # [foo](@ref) => foo
push!(repls, r"\[([^]]+?)\]\(@ref .*?\)"s => s"\1") # [foo](@ref bar) => foo push!(repls, r"\[([^]]+?)\]\(@ref .*?\)"s => s"\1") # [foo](@ref bar) => foo
push!(repls, r"\[([^]]+?)\]\(@extref\)"s => s"\1") # [foo](@extref) => foo
push!(repls, r"\[([^]]+?)\]\(@extref .*?\)"s => s"\1") # [foo](@extref bar) => foo
push!(repls, r"\[([^]]+?)\]\(@id .*?\)"s => s"\1") # [foo](@id bar) => foo push!(repls, r"\[([^]]+?)\]\(@id .*?\)"s => s"\1") # [foo](@id bar) => foo
end end

6
test/runtests.jl

@ -220,6 +220,7 @@ end # testset parser
content = """ content = """
# # [Example](@id example-id) # # [Example](@id example-id)
# [foo](@ref), [bar](@ref bbaarr) # [foo](@ref), [bar](@ref bbaarr)
# [baz](@extref), [bax](@extref bbaaxx)
x = 1 x = 1
#md # Only markdown #md # Only markdown
# Only markdown #md # Only markdown #md
@ -580,6 +581,7 @@ end end
# [Example](@id example-id) # [Example](@id example-id)
[foo](@ref), [bar](@ref bbaarr) [foo](@ref), [bar](@ref bbaarr)
[baz](@extref), [bax](@extref bbaaxx)
````@example inputfile ````@example inputfile
x = 1 x = 1
@ -1027,7 +1029,8 @@ end end
""" """
"source": [ "source": [
"# Example\\n", "# Example\\n",
"foo, bar" "foo, bar\\n",
"baz, bax"
] ]
""", """,
@ -1263,6 +1266,7 @@ end end
notebook = read(joinpath(outdir, "inputfile.ipynb"), String) notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@test !occursin("# [Example](@id example-id", notebook) @test !occursin("# [Example](@id example-id", notebook)
@test !occursin("[foo](@ref), [bar](@ref bbaarr)", notebook) @test !occursin("[foo](@ref), [bar](@ref bbaarr)", notebook)
@test !occursin("[baz](@ref), [bax](@ref bbaaxx)", notebook)
# name # name
Literate.notebook(inputfile, outdir, name = "foobar", execute = false) Literate.notebook(inputfile, outdir, name = "foobar", execute = false)

Loading…
Cancel
Save