From e410613aa47bfc98853f5617c7655d67cadfb2e3 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Sat, 9 May 2020 20:23:18 +0200 Subject: [PATCH] HTML: Constrain
-specific elements to BodyContext MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change moves the APIs for creating what can be seen as “form-specific” HTML elements (such as `` and `
`) from an extension constrained to `HTML.FormContext` to the main `HTML.BodyContext` instead. This enables such elements to be mixed and matched with other body elements, such as `
`. While such elements might most often appear within forms, there’s nothing within the HTML spec that enforces that, so neither should Plot. --- Sources/Plot/API/HTMLElements.swift | 40 +++++++++++++---------------- Tests/PlotTests/HTMLTests.swift | 23 +++++++++++++++++ 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/Sources/Plot/API/HTMLElements.swift b/Sources/Plot/API/HTMLElements.swift index 37a248f..9dd54b8 100644 --- a/Sources/Plot/API/HTMLElements.swift +++ b/Sources/Plot/API/HTMLElements.swift @@ -188,6 +188,12 @@ public extension Node where Context: HTML.BodyContext { .selfClosedElement(named: "embed", attributes: attributes) } + /// Add a `
` HTML element within the current context. + /// - parameter nodes: The element's attributes and child elements. + static func fieldset(_ nodes: Node...) -> Node { + .element(named: "fieldset", nodes: nodes) + } + /// Add a `` HTML element within the current context. /// - parameter nodes: The element's attributes and child elements. static func form(_ nodes: Node...) -> Node { @@ -259,6 +265,12 @@ public extension Node where Context: HTML.BodyContext { .element(named: "iframe", attributes: attributes) } + /// Add an `` HTML element within the current context. + /// - parameter nodes: The element's attributes. + static func input(_ attributes: Attribute...) -> Node { + .selfClosedElement(named: "input", attributes: attributes) + } + /// Add an `` HTML element within the current context. /// - parameter nodes: The element's attributes and child elements. static func ins(_ nodes: Node...) -> Node { @@ -349,6 +361,12 @@ public extension Node where Context: HTML.BodyContext { .element(named: "table", nodes: nodes) } + /// Add a `