Skip to content

Commit

Permalink
Do not fix link when the uri contains a schema (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
findmyway authored May 5, 2021
1 parent 53cd085 commit 7fe6cd4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Memoize = "c03570c3-d221-55d1-a50c-7939bbd78826"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
Tectonic = "9ac5f52a-99c6-489f-af81-462ef484790f"
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
pandoc_crossref_jll = "f96e3c25-ae70-5588-8d8e-4a7ab3ba4c45"
pandoc_jll = "c5432543-76ad-5c9d-82bf-db097047a5e2"
Expand All @@ -28,6 +29,7 @@ Memoize = "0.4"
Requires = "1.1"
TOML = "1.0"
Tectonic = "0.4"
URIs = "1"
YAML = "0.4"
julia = "1.6"
pandoc_crossref_jll = "0.3.9"
Expand Down
5 changes: 4 additions & 1 deletion src/html.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import YAML
import URIs

"""
split_keepdelim(str::AbstractString, dlm::Regex)
Expand Down Expand Up @@ -260,8 +261,10 @@ function fix_links(names, pages, url_prefix)
elseif startswith(capture, "#ref-")
page_link = "references"
return uncapture("$url_prefix/$page_link.html$capture")
else
elseif URIs.URI(URIs.unescapeuri(capture)).scheme == ""
return uncapture("$url_prefix$capture")
else
return uncapture(capture)
end
end
fixed = replace(page, rx => replace_match)
Expand Down
3 changes: 3 additions & 0 deletions test/html.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<link rel="stylesheet" href="/files/style.css"/>
<a href="#sec:foo">Foo</a>
<h2 data-number="3.5" id="sec:foo"><span class="header-section-number">3.5</span> Foo</h2>
<p> <a href="https://www.google.com">Jump</a></p>
"""
pages = [page]
docs_dir = joinpath(pkgdir(Books), "docs")
Expand All @@ -73,6 +74,7 @@
<link rel="stylesheet" href="/Books.jl/files/style.css"/>
<a href="/Books.jl/test.html#sec:foo">Foo</a>
<h2 data-number="3.5" id="sec:foo"><span class="header-section-number">3.5</span> Foo</h2>
<p> <a href="https://www.google.com">Jump</a></p>
"""
@test actual == expected
end
Expand All @@ -83,6 +85,7 @@
<link rel="stylesheet" href="/files/style.css"/>
<a href="/test.html#sec:foo">Foo</a>
<h2 data-number="3.5" id="sec:foo"><span class="header-section-number">3.5</span> Foo</h2>
<p> <a href="https://www.google.com">Jump</a></p>
"""
@test actual == expected
end
10 changes: 6 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ DocMeta.setdocmeta!(
)
doctest(Books)

include("output.jl")
include("html.jl")
include("showcode.jl")
include("generate.jl")
@testset "Books.jl" begin
include("output.jl")
include("html.jl")
include("showcode.jl")
include("generate.jl")
end

0 comments on commit 7fe6cd4

Please sign in to comment.