+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## Unreleased

- Fix [#4](https://github.com/borkdude/html/issues/4): support HTML5 by default (void tags)
17 changes: 17 additions & 0 deletions script/changelog.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bb

(ns changelog
(:require [clojure.string :as str]))

(let [changelog (slurp "CHANGELOG.md")
replaced (str/replace changelog
#" #(\d+)"
(fn [[_ issue after]]
(format " [#%s](https://github.com/borkdude/html/issues/%s)%s"
issue issue (str after))))
replaced (str/replace replaced
#"@([a-zA-Z0-9-_]+)([, \.)])"
(fn [[_ name after]]
(format "[@%s](https://github.com/%s)%s"
name name after)))]
(spit "CHANGELOG.md" replaced))
9 changes: 8 additions & 1 deletion src/borkdude/html.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
`(str ~acc ~x (str* ~@xs))))
acc)))

(def ^{:doc "A list of elements that must be rendered without a closing tag. From hiccup."
:private true}
void-tags
#{"area" "base" "br" "col" "command" "embed" "hr" "img" "input" "keygen" "link"
"meta" "param" "source" "track" "wbr"})

(defn reader [form]
(cond
(nil? form) nil
Expand All @@ -85,7 +91,8 @@
[(str "<" tag attrs ">")]
["<" tag " " attrs ">"]))
~@(map #(list `html %) children)
~(if omit-tag?
~(if (or omit-tag?
(contains? void-tags tag))
nil
(str "</" tag ">"))))))
(string? form) `(->Html ~(escape-html form))
Expand Down
8 changes: 3 additions & 5 deletions test/borkdude/html_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
"<a href=\"#\">Hi</a>"
(html [:a {:href "#"} "Hi"])

;; XHTML5?
"<hr></hr>"
(html [:hr])

"<div>&lt;script&gt;</div>"
(html [:div "<script>"])

Expand Down Expand Up @@ -62,7 +58,9 @@
(map (fn [i]
(html [:li i]))
[2 3])])
)

"<div><br></div>"
(html [:div [:br]]))

)

Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载