mirror of
https://github.com/MillironX/Kelpie.jl.git
synced 2024-11-14 21:43:10 +00:00
Merge pull request #3 from MillironX/html-node-fix
This commit is contained in:
commit
cdb16fde52
3 changed files with 44 additions and 24 deletions
|
@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
- Arrays of content replaced with argument splatting ([#2](https://github.com/MillironX/Kelpie.jl/pull/2))
|
- Arrays of content replaced with argument splatting ([#2](https://github.com/MillironX/Kelpie.jl/pull/2))
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- `html()` now returns an `<html>` node, not just a document ([#3](https://github.com/MillironX/Kelpie.jl/pull/3))
|
||||||
|
|
||||||
## [0.1.0] - 2022-04-04
|
## [0.1.0] - 2022-04-04
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
34
README.md
34
README.md
|
@ -60,22 +60,24 @@ Turns into
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
<!DOCTYPE html SYSTEM "about:legacy-compat">
|
||||||
<head>
|
<html>
|
||||||
<title>Kelpie.jl is awesome!</title>
|
<head>
|
||||||
</head>
|
<title>Kelpie.jl is awesome!</title>
|
||||||
<body>
|
</head>
|
||||||
<header>
|
<body>
|
||||||
<h1>Dogs are cool</h1>
|
<header>
|
||||||
<h2>Julia is cool</h2>
|
<h1>Dogs are cool</h1>
|
||||||
</header>
|
<h2>Julia is cool</h2>
|
||||||
<main>
|
</header>
|
||||||
<img src="/kelpie-on-sheep-back.jpg" alt="A Kelpie herding sheep" />
|
<main>
|
||||||
<p>Kelpies make great herding dogs for cows.</p>
|
<img src="/kelpie-on-sheep-back.jpg" alt="A Kelpie herding sheep" />
|
||||||
<p>Kelpies make great herding dogs for sheep.</p>
|
<p>Kelpies make great herding dogs for cows.</p>
|
||||||
<p>Kelpies make great herding dogs for chickens.</p>
|
<p>Kelpies make great herding dogs for sheep.</p>
|
||||||
</main>
|
<p>Kelpies make great herding dogs for chickens.</p>
|
||||||
</body>
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
```
|
```
|
||||||
|
|
||||||
Everything is pure Julia, so your imagination is the limit!
|
Everything is pure Julia, so your imagination is the limit!
|
||||||
|
|
|
@ -83,10 +83,12 @@ julia> prettyprint(link_or_text!(ElementNode("div"), "The end", ElementNode("hr"
|
||||||
"""
|
"""
|
||||||
function link_or_text!(node, content...)
|
function link_or_text!(node, content...)
|
||||||
for con in content
|
for con in content
|
||||||
if typeof(con) <: EzXML.Node
|
if !isnothing(con)
|
||||||
link!(node, con)
|
if typeof(con) <: EzXML.Node
|
||||||
else
|
link!(node, con)
|
||||||
link!(node, EzXML.TextNode(string(con)))
|
else
|
||||||
|
link!(node, EzXML.TextNode(string(con)))
|
||||||
|
end #if
|
||||||
end #if
|
end #if
|
||||||
end #for
|
end #for
|
||||||
|
|
||||||
|
@ -126,13 +128,25 @@ function html_element(name::AbstractString, content...=nothing; kwargs...)
|
||||||
end #function
|
end #function
|
||||||
|
|
||||||
"""
|
"""
|
||||||
html(content...)
|
html(content...=nothing; kwargs...)
|
||||||
|
|
||||||
Creates a new HTML document filled with `content`.
|
Creates a new HTML document filled with `content`.
|
||||||
|
|
||||||
|
# Example
|
||||||
|
|
||||||
|
```jldoctest
|
||||||
|
julia> import EzXML: prettyprint
|
||||||
|
|
||||||
|
julia> prettyprint(html())
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<!DOCTYPE html SYSTEM "about:legacy-compat">
|
||||||
|
<html/>
|
||||||
|
```
|
||||||
"""
|
"""
|
||||||
function html(content...)
|
function html(content...=nothing; kwargs...)
|
||||||
doc = EzXML.HTMLDocumentNode(nothing, nothing)
|
doc = EzXML.HTMLDocumentNode("about:legacy-compat", nothing)
|
||||||
link_or_text!(doc, content...)
|
node = html_element("html", content...; kwargs...)
|
||||||
|
link!(doc, node)
|
||||||
return doc
|
return doc
|
||||||
end #function
|
end #function
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue