Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb05374e

Browse files
authored
Assets: allow passing direct HTML content intoasset kwarg (for Pluto support) (#2726)
1 parent8eb9ee1 commitb05374e

File tree

9 files changed

+40
-8
lines changed

9 files changed

+40
-8
lines changed

‎CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
44
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6+
## Version [v1.13.0] - 2025-06-19
7+
8+
### Added
9+
10+
* Added new type `RawHTMLHeadContent` to `HTML` format object, which allows to add raw HTML to the head of the HTML output, by passing it as a element in the `assets` keyword argument. ([#2726])
11+
612
## Version [v1.12.0] - 2025-06-06
713

814
### Added
@@ -1538,6 +1544,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
15381544
[v1.11.3]: https://github.com/JuliaDocs/Documenter.jl/releases/tag/v1.11.3
15391545
[v1.11.4]: https://github.com/JuliaDocs/Documenter.jl/releases/tag/v1.11.4
15401546
[v1.12.0]: https://github.com/JuliaDocs/Documenter.jl/releases/tag/v1.12.0
1547+
[v1.13.0]: https://github.com/JuliaDocs/Documenter.jl/releases/tag/v1.13.0
15411548
[#198]: https://github.com/JuliaDocs/Documenter.jl/issues/198
15421549
[#245]: https://github.com/JuliaDocs/Documenter.jl/issues/245
15431550
[#487]: https://github.com/JuliaDocs/Documenter.jl/issues/487
@@ -2105,6 +2112,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21052112
[#2721]: https://github.com/JuliaDocs/Documenter.jl/issues/2721
21062113
[#2722]: https://github.com/JuliaDocs/Documenter.jl/issues/2722
21072114
[#2723]: https://github.com/JuliaDocs/Documenter.jl/issues/2723
2115+
[#2726]: https://github.com/JuliaDocs/Documenter.jl/issues/2726
21082116
[#2729]: https://github.com/JuliaDocs/Documenter.jl/issues/2729
21092117
[#2737]: https://github.com/JuliaDocs/Documenter.jl/issues/2737
21102118
[JuliaLang/julia#36953]: https://github.com/JuliaLang/julia/issues/36953

‎Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name ="Documenter"
22
uuid ="e30172f5-a6a5-5a46-863b-614d45cd2de4"
3-
version ="1.12.0"
3+
version ="1.13.0"
44

55
[deps]
66
ANSIColoredPrinters ="a4c015fc-c6ff-483c-b24f-f7ea428134e9"

‎docs/src/lib/internals/writers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Modules = [
1111
Documenter.HTMLWriter.RD,
1212
Documenter.LaTeXWriter,
1313
]
14-
Filter = t -> t!==asset
14+
Filter = t -> t∉ (asset, RawHTMLHeadContent)
1515
Pages = ["writers.jl", "html/HTMLWriter.jl", "html/RD.jl", "html/write_inventory.jl", "latex/LaTeXWriter.jl"]
1616
```
1717
```@docs

‎docs/src/lib/public.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Documenter.except
2626
hide
2727
Documenter.MissingRemoteError
2828
asset
29+
RawHTMLHeadContent
2930
deploydocs
3031
doctest
3132
DocMeta

‎src/Documenter.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ module Writers
9393
import..HTMLWriter
9494
end
9595

96-
import.HTMLWriter: HTML, asset
96+
import.HTMLWriter: HTML, asset, RawHTMLHeadContent
9797
import.HTMLWriter.RD: KaTeX, MathJax, MathJax2, MathJax3
9898
import.LaTeXWriter: LaTeX
9999

100100
# User Interface.
101101
# ---------------
102-
export makedocs, deploydocs, hide, doctest, DocMeta, asset, Remotes,
102+
export makedocs, deploydocs, hide, doctest, DocMeta, asset,RawHTMLHeadContent,Remotes,
103103
KaTeX, MathJax, MathJax2, MathJax3
104104

105105
include("makedocs.jl")

‎src/html/HTMLWriter.jl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ const ASSETS_SASS = joinpath(ASSETS, "scss")
9292
"Directory for the compiled CSS files of the themes."
9393
const ASSETS_THEMES=joinpath(ASSETS,"themes")
9494

95-
struct HTMLAsset
95+
abstract type HTMLHeadContentend
96+
97+
struct HTMLAsset<:HTMLHeadContent
9698
class::Symbol
9799
uri::String
98100
islocal::Bool
@@ -110,6 +112,16 @@ struct HTMLAsset
110112
end
111113
end
112114

115+
"""
116+
RawHTMLHeadContent(content::String)
117+
118+
Raw HTML content to be inserted into the `<head>` section of the HTML document. This type can
119+
be used in the `assets` keyword of [`HTML`](@ref), just like [`asset`](@ref).
120+
"""
121+
struct RawHTMLHeadContent<:HTMLHeadContent
122+
content::String
123+
end
124+
113125
"""
114126
asset(uri)
115127
@@ -469,7 +481,7 @@ struct HTML <: Documenter.Writer
469481
edit_link::Union{String, Symbol, Nothing}
470482
repolink::Union{String, Nothing, Default{Nothing}}
471483
canonical::Union{String, Nothing}
472-
assets::Vector{HTMLAsset}
484+
assets::Vector{<:HTMLHeadContent}
473485
analytics::String
474486
collapselevel::Int
475487
sidebar_sitename::Bool
@@ -526,7 +538,7 @@ struct HTML <: Documenter.Writer
526538
prerender, node, highlightjs=prepare_prerendering(prerender, node, highlightjs, highlights)
527539
end
528540
assets=map(assets)do asset
529-
isa(asset,HTMLAsset)&&return asset
541+
isa(asset,HTMLHeadContent)&&return asset
530542
isa(asset, AbstractString)&&returnHTMLAsset(assetclass(asset), asset,true)
531543
error("Invalid value in assets:$(asset) [$(typeof(asset))]")
532544
end
@@ -1101,11 +1113,15 @@ function find_preview_image(ctx)
11011113
returnnothing
11021114
end
11031115

1104-
functionasset_links(src::AbstractString, assets::Vector{HTMLAsset})
1116+
functionasset_links(src::AbstractString, assets::Vector{<:HTMLHeadContent})
11051117
isabspath(src)&&@error("Absolute path '$src' passed to asset_links")
11061118
@tags link script
11071119
links= DOM.Node[]
11081120
for assetin assets
1121+
ifisa(asset, RawHTMLHeadContent)
1122+
push!(links, DOM.Tag(Symbol("#RAW#"))(asset.content))
1123+
continue
1124+
end
11091125
class= asset.class
11101126
url= asset.islocal?relhref(src, asset.uri): asset.uri
11111127
node=

‎test/examples/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ examples_html_local_doc = if "html-local" in EXAMPLE_BUILDS
436436
assets= [
437437
"assets/custom.css",
438438
asset("https://plausible.io/js/plausible.js", class=:js, attributes=Dict(Symbol("data-domain")=>"example.com",:defer=>"")),
439+
RawHTMLHeadContent("<script>console.log('hello from head content! 🌸')</script>"),
439440
],
440441
prettyurls=false,
441442
footer=nothing,

‎test/examples/tests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ end
394394
documenterjs=String(read(joinpath(build_dir,"assets","documenter.js")))
395395
@testoccursin("languages/julia.min", documenterjs)
396396
@testoccursin("languages/julia-repl.min", documenterjs)
397+
let
398+
example_output_html=read(joinpath(build_dir,"example-output.html"), String)
399+
example_head=match(r"<head>(.*?)</head>"ms, example_output_html).captures[1]
400+
@testoccursin("<script>console.log('hello from head content! 🌸')</script>", example_head)
401+
end
397402

398403
@testset"at-example outputs:$fmt/$size"for ((fmt, size), data)in AT_EXAMPLE_FILES
399404
if size===:tiny

‎test/htmlwriter.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ end
112112

113113
# HTML format object
114114
@test Documenter.HTML()isa Documenter.HTML
115+
@test Documenter.HTML(assets= [RawHTMLHeadContent("<!-- hello -->")])isa Documenter.HTML
115116
@test_throws ArgumentError Documenter.HTML(collapselevel=-200)
116117
@test_throws Exception Documenter.HTML(assets= ["foo.js",10])
117118
@test_throws ArgumentError Documenter.HTML(footer="foo\n\nbar")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp