Initial Commit
This commit is contained in:
193
Sources/HRW/GenHTML/Elements/Link.swift
Normal file
193
Sources/HRW/GenHTML/Elements/Link.swift
Normal file
@@ -0,0 +1,193 @@
|
||||
//
|
||||
// Link.swift
|
||||
// HTMLStandard
|
||||
//
|
||||
// Generated on 09/23/2025.
|
||||
// THIS FILE IS GENERATED. DO NOT EDIT.
|
||||
//
|
||||
import Foundation
|
||||
|
||||
/// <link> Link metadata
|
||||
public class Link : HTMLNode, IFlow, IMetaData, IPhrasing {
|
||||
|
||||
public enum Crossorigin : String, CaseIterable {
|
||||
|
||||
case anonymous
|
||||
case useCredentials = "use-credentials"
|
||||
|
||||
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 Crossorigin: \(expect)") }
|
||||
|
||||
self = value
|
||||
}
|
||||
|
||||
public init(expect: String) throws {
|
||||
guard let result = Crossorigin(rawValue: expect) else {
|
||||
throw AppError("Unexpected value for Crossorigin: \(expect)")
|
||||
}
|
||||
self = result
|
||||
}
|
||||
|
||||
static func parseList(_ value:String?, _ separator:String = " ") throws -> [Crossorigin] {
|
||||
guard let value = value else { return [] }
|
||||
var iterator = value.componentsIterator(separatedBy: separator)
|
||||
let result = try iterator.map { input in
|
||||
return try expect(Crossorigin(rawValue: input), "unexpected value for Crossorigin: \(input)")
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
/// Potential destination for a preload request (for rel="preload" and rel="modulepreload"). Potential destination, for rel="preload"; script-like destination, for rel="modulepreload".
|
||||
public var as_:String? = nil
|
||||
|
||||
/// How the element handles crossorigin requests.
|
||||
public var crossorigin:Crossorigin? = nil
|
||||
|
||||
/// Address of the hyperlink. Valid non-empty URL potentially surrounded by spaces.
|
||||
public var href:URL? = nil
|
||||
|
||||
/// Language of the linked resource. Valid BCP 47 language tag.
|
||||
public var hreflang:String? = nil
|
||||
|
||||
/// Image sizes for different page layouts. Valid source size list.
|
||||
public var imagesizes:[String] = []
|
||||
|
||||
/// Images to use in different situations (e.g., high-resolution displays, small monitors, etc.). Comma-separated list of image candidate strings.
|
||||
public var imagesrcset:[String] = []
|
||||
|
||||
/// Integrity metadata used in Subresource Integrity checks [SRI].
|
||||
public var integrity:String? = nil
|
||||
|
||||
/// Applicable media. Valid media query list.
|
||||
public var media:String? = nil
|
||||
|
||||
/// Referrer policy for fetches initiated by the element. Referrer policy.
|
||||
public var referrerpolicy:ReferrerPolicy? = nil
|
||||
|
||||
/// Relationship between the document containing the hyperlink and the destination resource. Unordered set of unique space-separated tokens. The actual rules are more complicated than indicated.
|
||||
public var rel:[String] = []
|
||||
|
||||
/// Sizes of the icons (for rel="icon"). Unordered set of unique space-separated tokens, ASCII case-insensitive, consisting of sizes. The actual rules are more complicated than indicated.
|
||||
public var sizes:[String] = []
|
||||
|
||||
/// Title of the link or CSS style sheet set name. Text or Text
|
||||
public var title:String? = nil
|
||||
|
||||
/// Hint for the type of the referenced resource. Valid MIME type string.
|
||||
public var type:String? = nil
|
||||
|
||||
|
||||
public init(_ attributes:[String:String], _ parser:XMLParser? = nil) throws {
|
||||
var globalAttr = GlobalAttributesBuilder()
|
||||
for (key, attValue) in attributes {
|
||||
switch (key) {
|
||||
case "as":
|
||||
as_ = attValue
|
||||
continue
|
||||
case "crossorigin":
|
||||
crossorigin = try Crossorigin(expect: attValue)
|
||||
continue
|
||||
case "href":
|
||||
href = try URL(expect: attValue)
|
||||
continue
|
||||
case "hreflang":
|
||||
hreflang = attValue
|
||||
continue
|
||||
case "imagesizes":
|
||||
imagesizes = try String.parseList(attValue, ",")
|
||||
continue
|
||||
case "imagesrcset":
|
||||
imagesrcset = try String.parseList(attValue, ",")
|
||||
continue
|
||||
case "integrity":
|
||||
integrity = attValue
|
||||
continue
|
||||
case "media":
|
||||
media = attValue
|
||||
continue
|
||||
case "referrerpolicy":
|
||||
referrerpolicy = try ReferrerPolicy(expect: attValue)
|
||||
continue
|
||||
case "rel":
|
||||
rel = try String.parseList(attValue, " ")
|
||||
continue
|
||||
case "sizes":
|
||||
sizes = try String.parseList(attValue, " ")
|
||||
continue
|
||||
case "title":
|
||||
title = attValue
|
||||
continue
|
||||
case "type":
|
||||
type = 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 as_ = as_ {
|
||||
result += " as='\(as_)'"
|
||||
}
|
||||
if let crossorigin = crossorigin {
|
||||
result += " crossorigin='\(crossorigin.rawValue)'"
|
||||
}
|
||||
if let href = href {
|
||||
result += " href='\(href.absoluteString)'"
|
||||
}
|
||||
if let hreflang = hreflang {
|
||||
result += " hreflang='\(hreflang)'"
|
||||
}
|
||||
result += " imagesizes='\(imagesizes.toStringList(","))'"
|
||||
result += " imagesrcset='\(imagesrcset.toStringList(","))'"
|
||||
if let integrity = integrity {
|
||||
result += " integrity='\(integrity)'"
|
||||
}
|
||||
if let media = media {
|
||||
result += " media='\(media)'"
|
||||
}
|
||||
if let referrerpolicy = referrerpolicy {
|
||||
result += " referrerpolicy='\(referrerpolicy.rawValue)'"
|
||||
}
|
||||
result += " rel='\(rel.toStringList(" "))'"
|
||||
result += " sizes='\(sizes.toStringList(" "))'"
|
||||
if let title = title {
|
||||
result += " title='\(title)'"
|
||||
}
|
||||
if let type = type {
|
||||
result += " type='\(type)'"
|
||||
}
|
||||
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
override var nodeName: String {
|
||||
return "link"
|
||||
}
|
||||
|
||||
override var isVoidElement: Bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user