@@ -5,21 +5,23 @@ import Foundation
55
66// MARK: Custom rendering
77extension HTML {
8+ @inlinable
89 func render( includeTag: Bool ) -> ( HTMLType , String ) {
9- if let node: HTMLNode = self as? HTMLNode {
10+ if let node = self as? HTMLNode {
1011 return ( . node, node. rendered ( includeTag: includeTag) )
11- } else if let node: MultiNode = self as? MultiNode {
12+ } else if let node = self as? MultiNode {
1213 var string : String = " "
1314 for child in node. children {
1415 string += child. render ( includeTag: true ) . 1
1516 }
1617 return ( . node, string)
17- } else if let node: AttributedNode = self as? AttributedNode {
18+ } else if let node = self as? AttributedNode {
1819 return ( . node, node. render)
1920 } else {
2021 return ( . node, String ( describing: self ) )
2122 }
2223 }
24+ @inlinable
2325 func isVoid( _ tag: String ) -> Bool {
2426 switch tag {
2527 case " area " , " base " , " br " , " col " , " embed " , " hr " , " img " , " input " , " link " , " meta " , " source " , " track " , " wbr " : return true
@@ -28,31 +30,32 @@ extension HTML {
2830 }
2931}
3032
31- enum HTMLType {
33+ public enum HTMLType {
3234 case node, attribute
3335}
3436
3537extension AttributedNode {
36- var render : String {
37- let tag : String = child. getTag ( ) !
38- let attribute_string : String = " " + attribute. key + ( attribute. value != nil ? " = \" " + attribute. value! + " \" " : " " )
38+ @inlinable
39+ var render : String {
40+ let tag = child. getTag ( ) !
41+ let attribute_string = " " + attribute. key + ( attribute. value != nil ? " = \" " + attribute. value! + " \" " : " " )
3942 return " < " + tag + attribute_string + " > " + child. render ( includeTag: false ) . 1 + ( isVoid ( tag) ? " " : " </ " + tag + " > " )
4043 }
4144}
4245
4346extension HTMLNode {
47+ @inlinable
4448 func rendered( includeTag: Bool ) -> String {
45- guard let tag: String = getTag ( ) else { return String ( describing: self ) }
46- var attributes : String = " " , children : String = " "
49+ guard let tag = getTag ( ) else { return String ( describing: self ) }
50+ var attributes = " "
51+ var children = " "
4752 if let child = self . child {
48- let ( type, value) : ( HTMLType , String ) = child. render ( includeTag: true )
53+ let ( type, value) = child. render ( includeTag: true )
4954 switch type {
50- case . attribute:
51- attributes += " " + value
52- break
53- case . node:
54- children += value
55- break
55+ case . attribute:
56+ attributes += " " + value
57+ case . node:
58+ children += value
5659 }
5760 }
5861 return ( tag == " html " ? " <!DOCTYPE html> " : " " ) + ( includeTag ? " < " + tag + attributes + " > " : " " ) + children + ( !isVoid( tag) && includeTag ? " </ " + tag + " > " : " " )
0 commit comments