Skip to content

Commit

Permalink
Fix slugify removing leading numeric digits (#2325)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Nov 2, 2023
1 parent 77f0bdd commit a13ef9a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## UNRELEASED

### Changed

* `id` anchors may now start with a numeric digit. ([#744]), ([#2325])

### Fixed

* Enabled text wrapping in docstring header on smaller screens. ([#2293], [#2307])
Expand Down Expand Up @@ -1289,6 +1293,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#631]: https://github.com/JuliaDocs/Documenter.jl/issues/631
[#697]: https://github.com/JuliaDocs/Documenter.jl/issues/697
[#706]: https://github.com/JuliaDocs/Documenter.jl/issues/706
[#744]: https://github.com/JuliaDocs/Documenter.jl/issues/744
[#756]: https://github.com/JuliaDocs/Documenter.jl/issues/756
[#764]: https://github.com/JuliaDocs/Documenter.jl/issues/764
[#774]: https://github.com/JuliaDocs/Documenter.jl/issues/774
Expand Down Expand Up @@ -1729,6 +1734,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#2300]: https://github.com/JuliaDocs/Documenter.jl/issues/2300
[#2307]: https://github.com/JuliaDocs/Documenter.jl/issues/2307
[#2317]: https://github.com/JuliaDocs/Documenter.jl/issues/2317
[#2323]: https://github.com/JuliaDocs/Documenter.jl/issues/2325
[JuliaLang/julia#29344]: https://github.com/JuliaLang/julia/issues/29344
[JuliaLang/julia#36953]: https://github.com/JuliaLang/julia/issues/36953
[JuliaLang/julia#38054]: https://github.com/JuliaLang/julia/issues/38054
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ Slugify a string into a suitable URL.
"""
function slugify(s::AbstractString)
s = replace(s, r"\s+" => "-")
s = replace(s, r"^\d+" => "")
s = replace(s, r"&" => "-and-")
s = replace(s, r"[^\p{L}\p{P}\d\-]+" => "")
s = strip(replace(s, r"\-\-+" => "-"), '-')
return s
end
slugify(object) = string(object) # Non-string slugifying doesn't do anything.

Expand Down
31 changes: 31 additions & 0 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,37 @@ end
@test remove_common_backtrace([1,2,3], [1,2,3]) == []
@test remove_common_backtrace([1,2,3], [0,1,2,3]) == []
end

@testset "slugify" begin
for (test, answer) in [
# Nonstrings get converted to strings
1 => "1",
# Good strings stay good
"a" => "a",
"my-heading" => "my-heading",
"documenter.jl/abc" => "documenter.jl/abc",
"https://documenter.jl/abc" => "https://documenter.jl/abc",
"2nd" => "2nd",
"2nd-2" => "2nd-2",
"123" => "123",
"123a" => "123a",
# Spaces get replaced by -
"2nd feature" => "2nd-feature",
# & gets replaced by -and-
"a & b" => "a-and-b",
# Multiple -- are reduced
"a---b" => "a-b",
# Leading and trailing - are stripped
"-a---b-" => "a-b",
# A combination of things
" a & b" => "a-and-b",
"--a & b" => "a-and-b",
# Non letter, punctuation, digit, or `-` characters are removed
"a\0a" => "aa"
]
@test Documenter.slugify(test) == answer
end
end
end

end

0 comments on commit a13ef9a

Please sign in to comment.