Skip to content

Commit fc0119c

Browse files
fixed meta attribute httpEquiv behavior
1 parent 08a37f5 commit fc0119c

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Sources/HTMLKitMacros/HTMLElement.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ private extension HTMLElement {
122122
} else {
123123
if key == "acceptCharset" {
124124
key = "accept-charset"
125+
} else if key == "httpEquiv" {
126+
key = "http-equiv"
125127
}
126128
if let string:String = parse_attribute(context: context, elementType: elementType, key: key, expression: child.expression, lookupFiles: lookupFiles) {
127129
attributes += string + " "
@@ -238,12 +240,13 @@ private extension HTMLElement {
238240

239241
static func enumName(elementType: HTMLElementType, key: String) -> String {
240242
switch elementType.rawValue + key {
241-
case "buttontype": return "buttontype"
242-
case "formenctype": return "formenctype"
243-
case "inputtype": return "inputtype"
244-
case "oltype": return "numberingtype"
245-
case "scripttype": return "scripttype"
246-
default: return key
243+
case "buttontype": return "buttontype"
244+
case "formenctype": return "formenctype"
245+
case "inputtype": return "inputtype"
246+
case "metahttp-equiv": return "httpequiv"
247+
case "oltype": return "numberingtype"
248+
case "scripttype": return "scripttype"
249+
default: return key
247250
}
248251
}
249252

Tests/HTMLKitTests/ElementTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,13 @@ extension ElementTests {
254254
#expect(string == "<link imagesrcset=\"blah,bling\">")
255255
}
256256

257+
// MARK: meta
258+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
259+
@Test func meta() {
260+
let string:StaticString = #meta(charset: "utf-8", httpEquiv: .contentType)
261+
#expect(string == "<meta charset=\"utf-8\" http-equiv=\"content-type\">")
262+
}
263+
257264
// MARK: ol
258265
@Test func ol() {
259266
var string:StaticString = #ol()

0 commit comments

Comments
 (0)