162 lines
4.9 KiB
Swift
162 lines
4.9 KiB
Swift
//
|
|
// Meta.swift
|
|
// HTMLStandard
|
|
//
|
|
// Generated on 09/23/2025.
|
|
// THIS FILE IS GENERATED. DO NOT EDIT.
|
|
//
|
|
import Foundation
|
|
|
|
/// <meta> Text metadata
|
|
public class Meta : HTMLNode, IFlow, IMetaData, IPhrasing {
|
|
|
|
public enum Charset : String, CaseIterable {
|
|
|
|
case utf8 = "utf-8"
|
|
|
|
public init?(rawValue: Substring) {
|
|
guard
|
|
let value = Self.allCases.first(where: { $0.rawValue == rawValue })
|
|
else
|
|
{ return nil }
|
|
|
|
self = value
|
|
}
|
|
|
|
public init(expect: Substring) throws {
|
|
guard
|
|
let value = Self.allCases.first(where: { $0.rawValue == expect })
|
|
else
|
|
{ throw AppError("Unexpected value for Charset: \(expect)") }
|
|
|
|
self = value
|
|
}
|
|
|
|
public init(expect: String) throws {
|
|
guard let result = Charset(rawValue: expect) else {
|
|
throw AppError("Unexpected value for Charset: \(expect)")
|
|
}
|
|
self = result
|
|
}
|
|
|
|
static func parseList(_ value:String?, _ separator:String = " ") throws -> [Charset] {
|
|
guard let value = value else { return [] }
|
|
var iterator = value.componentsIterator(separatedBy: separator)
|
|
let result = try iterator.map { input in
|
|
return try expect(Charset(rawValue: input), "unexpected value for Charset: \(input)")
|
|
}
|
|
return result
|
|
}
|
|
}
|
|
|
|
public enum Http_equiv : String, CaseIterable {
|
|
|
|
case contentSecurityPolicy = "content-security-policy"
|
|
case contentType = "content-type"
|
|
case defaultStyle = "default-style"
|
|
case refresh
|
|
case xUaCompatible = "x-ua-compatible"
|
|
|
|
public init?(rawValue: Substring) {
|
|
guard
|
|
let value = Self.allCases.first(where: { $0.rawValue == rawValue })
|
|
else
|
|
{ return nil }
|
|
|
|
self = value
|
|
}
|
|
|
|
public init(expect: Substring) throws {
|
|
guard
|
|
let value = Self.allCases.first(where: { $0.rawValue == expect })
|
|
else
|
|
{ throw AppError("Unexpected value for Http_equiv: \(expect)") }
|
|
|
|
self = value
|
|
}
|
|
|
|
public init(expect: String) throws {
|
|
guard let result = Http_equiv(rawValue: expect) else {
|
|
throw AppError("Unexpected value for Http_equiv: \(expect)")
|
|
}
|
|
self = result
|
|
}
|
|
|
|
static func parseList(_ value:String?, _ separator:String = " ") throws -> [Http_equiv] {
|
|
guard let value = value else { return [] }
|
|
var iterator = value.componentsIterator(separatedBy: separator)
|
|
let result = try iterator.map { input in
|
|
return try expect(Http_equiv(rawValue: input), "unexpected value for Http_equiv: \(input)")
|
|
}
|
|
return result
|
|
}
|
|
}
|
|
|
|
/// Character encoding declaration.
|
|
public var charset:Charset? = nil
|
|
|
|
/// Value of the element. Text. The actual rules are more complicated than indicated.
|
|
public var content:String? = nil
|
|
|
|
/// Pragma directive.
|
|
public var http_equiv:Http_equiv? = nil
|
|
|
|
/// Metadata name. Text. The actual rules are more complicated than indicated.
|
|
public var name:String? = nil
|
|
|
|
|
|
public init(_ attributes:[String:String], _ parser:XMLParser? = nil) throws {
|
|
var globalAttr = GlobalAttributesBuilder()
|
|
for (key, attValue) in attributes {
|
|
switch (key) {
|
|
case "charset":
|
|
charset = try Charset(expect: attValue)
|
|
continue
|
|
case "content":
|
|
content = attValue
|
|
continue
|
|
case "http-equiv":
|
|
http_equiv = try Http_equiv(expect: attValue)
|
|
continue
|
|
case "name":
|
|
name = attValue
|
|
continue
|
|
|
|
default: break
|
|
}
|
|
if globalAttr.trySetGlobalAttribute(key, attValue) {
|
|
continue
|
|
}
|
|
throw AppError("Unexpected attribute: \(key)")
|
|
}
|
|
super.init(globalAttr)
|
|
}
|
|
|
|
|
|
public override func renderAttributes() -> String {
|
|
var result = super.renderAttributes()
|
|
if let charset = charset {
|
|
result += " charset='\(charset.rawValue)'"
|
|
}
|
|
if let content = content {
|
|
result += " content='\(content)'"
|
|
}
|
|
if let http_equiv = http_equiv {
|
|
result += " http-equiv='\(http_equiv.rawValue)'"
|
|
}
|
|
if let name = name {
|
|
result += " name='\(name)'"
|
|
}
|
|
|
|
|
|
return result
|
|
}
|
|
|
|
override var nodeName: String {
|
|
return "meta"
|
|
}
|
|
|
|
override var isVoidElement: Bool {
|
|
return true
|
|
}
|
|
} |