Skip to content

Commit

Permalink
Remove at-extref from non-Documenter output (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
musoke authored Apr 16, 2024
1 parent 65e8796 commit 142bbee
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/),
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
### Added
- Literate can now output [Quarto](https://quarto.org/) notebooks (markdown documents with
Expand Down Expand Up @@ -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
[#230]: https://github.com/fredrikekre/Literate.jl/issues/230
[#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
[0f9e836]: https://github.com/fredrikekre/Literate.jl/commit/0f9e836
[1d02868]: https://github.com/fredrikekre/Literate.jl/commit/1d02868
Expand Down
8 changes: 4 additions & 4 deletions docs/src/documenter.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ if we set `documenter = true`:
````

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

### [`Literate.script`](@ref):
- Documenter style `@ref`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.
- Documenter style `@ref`s, `@extref`s and `@id` will be removed. This means that you can use
`@ref`, `@extref` and `@id` in the source file without them leaking to the script.
4 changes: 3 additions & 1 deletion src/Literate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,11 @@ function replace_default(content, sym;

# Run some Documenter specific things
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 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
end

Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ end # testset parser
content = """
# # [Example](@id example-id)
# [foo](@ref), [bar](@ref bbaarr)
# [baz](@extref), [bax](@extref bbaaxx)
x = 1
#md # Only markdown
# Only markdown #md
Expand Down Expand Up @@ -580,6 +581,7 @@ end end
# [Example](@id example-id)
[foo](@ref), [bar](@ref bbaarr)
[baz](@extref), [bax](@extref bbaaxx)
````@example inputfile
x = 1
Expand Down Expand Up @@ -1027,7 +1029,8 @@ end end
"""
"source": [
"# Example\\n",
"foo, bar"
"foo, bar\\n",
"baz, bax"
]
""",

Expand Down Expand Up @@ -1263,6 +1266,7 @@ end end
notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@test !occursin("# [Example](@id example-id", notebook)
@test !occursin("[foo](@ref), [bar](@ref bbaarr)", notebook)
@test !occursin("[baz](@ref), [bax](@ref bbaaxx)", notebook)

# name
Literate.notebook(inputfile, outdir, name = "foobar", execute = false)
Expand Down

0 comments on commit 142bbee

Please sign in to comment.