1
0
Fork 0
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:
Thomas A. Christensen II 2022-04-05 20:56:21 +00:00 committed by GitHub
commit cdb16fde52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 24 deletions

View file

@ -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

View file

@ -60,7 +60,8 @@ 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">
<html>
<head> <head>
<title>Kelpie.jl is awesome!</title> <title>Kelpie.jl is awesome!</title>
</head> </head>
@ -76,6 +77,7 @@ Turns into
<p>Kelpies make great herding dogs for chickens.</p> <p>Kelpies make great herding dogs for chickens.</p>
</main> </main>
</body> </body>
</html>
``` ```
Everything is pure Julia, so your imagination is the limit! Everything is pure Julia, so your imagination is the limit!

View file

@ -83,11 +83,13 @@ 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 !isnothing(con)
if typeof(con) <: EzXML.Node if typeof(con) <: EzXML.Node
link!(node, con) link!(node, con)
else else
link!(node, EzXML.TextNode(string(con))) link!(node, EzXML.TextNode(string(con)))
end #if end #if
end #if
end #for end #for
return node return node
@ -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