-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathElements.swift
1867 lines (1632 loc) · 72.6 KB
/
Elements.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
public func element<T>(_ name: StaticString, _ attribs: [Attribute<T>], _ children: [Node]) -> Node {
return .element(String(describing: name), attribs.map { ($0.key, $0.value) }, children)
}
public func element(_ name: StaticString, _ children: [Node]) -> Node {
return .element(String(describing: name), [], children)
}
public struct ChildOf<T> {
public let rawValue: Node
public init(_ node: Node) {
self.rawValue = node
}
}
public enum Tag {
public enum A {}
public enum Abbr {}
public enum Address {}
public enum Area {}
public enum Article {}
public enum Aside {}
public enum Audio {}
public enum B {}
public enum Base {}
public enum Bdi {}
public enum Bdo {}
public enum Blockquote {}
public enum Body {}
public enum Button {}
public enum Canvas {}
public enum Caption {}
public enum Cite {}
public enum Code {}
public enum Col {}
public enum Colgroup {}
public enum Dd {}
public enum Del {}
public enum Details {}
public enum Dfn {}
public enum Div {}
public enum Dl {}
public enum Dt {}
public enum Em {}
public enum Embed {}
public enum Fieldset {}
public enum Figcaption {}
public enum Figure {}
public enum Footer {}
public enum Form {}
public enum H1 {}
public enum H2 {}
public enum H3 {}
public enum H4 {}
public enum H5 {}
public enum H6 {}
public enum Head {}
public enum Header {}
public enum Hr {}
public enum Html {}
public enum I {}
public enum Iframe {}
public enum Img {}
public enum Input {}
public enum Ins {}
public enum Kbd {}
public enum Label {}
public enum Legend {}
public enum Li {}
public enum Link {}
public enum Main {}
public enum Mark {}
public enum Map {}
public enum Meta {}
public enum Meter {}
public enum Nav {}
public enum Object {}
public enum Ol {}
public enum Optgroup {}
public enum Option {}
public enum Output {}
public enum P {}
public enum Param {}
public enum Picture {}
public enum Pre {}
public enum Progress {}
public enum Q {}
public enum Rp {}
public enum Rt {}
public enum Ruby {}
public enum S {}
public enum Samp {}
public enum Script {}
public enum Section {}
public enum Select {}
public enum Small {}
public enum Source {}
public enum Span {}
public enum Strong {}
public enum Style {}
public enum Sub {}
public enum Summary {}
public enum Sup {}
public enum Svg {}
public enum Table {}
public enum Tbody {}
public enum Td {}
public enum Textarea {}
public enum Tfoot {}
public enum Time {}
public enum Track {}
public enum Th {}
public enum Thead {}
public enum Tr {}
public enum U {}
public enum Ul {}
public enum Var {}
public enum Video {}
}
/// The `<a>` element represents either a hyperlink (a hypertext anchor) labeled by its contents, or a placeholder for where a link might otherwise have been placed, if it had been relevant, consisting of just the element's contents.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func a(_ attribs: [Attribute<Tag.A>], _ content: [Node]) -> Node {
return element("a", attribs, content)
}
/// The `<a>` element represents either a hyperlink (a hypertext anchor) labeled by its contents, or a placeholder for where a link might otherwise have been placed, if it had been relevant, consisting of just the element's contents.
///
/// - Parameter content: Child nodes.
public func a(_ content: [Node]) -> Node {
return a([], content)
}
/// The `<abbr>` element represents an abbreviation or acronym, optionally with its expansion.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func abbr(_ attribs: [Attribute<Tag.Abbr>], _ content: [Node]) -> Node {
return element("abbr", attribs, content)
}
/// The `<abbr>` element represents an abbreviation or acronym, optionally with its expansion.
///
/// - Parameter content: Child nodes.
public func abbr(_ content: [Node]) -> Node {
return abbr([], content)
}
/// The `<address>` element represents contact information for a person, people or organization. It should include physical and/or digital location/contact information and a means of identifying a person(s) or organization the information pertains to.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func address(_ attribs: [Attribute<Tag.Address>], _ content: [Node]) -> Node {
return element("address", attribs, content)
}
/// The `<address>` element represents contact information for a person, people or organization. It should include physical and/or digital location/contact information and a means of identifying a person(s) or organization the information pertains to.
///
/// - Parameter content: Child nodes.
public func address(_ content: [Node]) -> Node {
return address([], content)
}
/// The `<area>` element represents either a hyperlink with some text and a corresponding area on an image
/// map, or a dead area on an image map.
public func area(_ attribs: [Attribute<Tag.Area>]) -> ChildOf<Tag.Map> {
return .init(element("area", attribs, []))
}
/// The `<article>` element represents a complete, or self-contained, composition in a document, page, application, or site. This could be a magazine, newspaper, technical or scholarly article, an essay or report, a blog or other social media post.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func article(_ attribs: [Attribute<Tag.Article>], _ content: [Node]) -> Node {
return element("article", attribs, content)
}
/// The `<article>` element represents a complete, or self-contained, composition in a document, page,
/// application, or site. This could be a magazine, newspaper, technical or scholarly article, an essay or
/// report, a blog or other social media post.
///
/// - Parameter content: Child nodes.
public func article(_ content: [Node]) -> Node {
return article([], content)
}
/// The `<aside>` element represents a section of a page that consists of content that is tangentially related to the content of the parenting sectioning content, and which could be considered separate from that content. Such sections are often represented as sidebars in printed typography.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func aside(_ attribs: [Attribute<Tag.Aside>], _ content: [Node]) -> Node {
return element("aside", attribs, content)
}
/// The `<aside>` element represents a section of a page that consists of content that is tangentially related to the content of the parenting sectioning content, and which could be considered separate from that content. Such sections are often represented as sidebars in printed typography.
///
/// - Parameter content: Child nodes.
public func aside(_ content: [Node]) -> Node {
return aside([], content)
}
/// An `<audio>` element represents a sound or audio stream.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
/// - transparent: Additional child nodes that render as content for older Web browsers which do not support `<audio>`
public func audio(
_ attribs: [Attribute<Tag.Audio>],
_ content: [ChildOf<Tag.Audio>],
_ transparent: [Node] = [])
-> Node {
return element("audio", attribs, content.map { $0.rawValue } + transparent)
}
/// An `<audio>` element represents a sound or audio stream.
///
/// - Parameter content: Child nodes.
/// - transparent: Additional child nodes that render as content for older Web browsers which do not support `<audio>`
public func audio(_ content: [ChildOf<Tag.Audio>], _ transparent: [Node] = []) -> Node {
return audio([], content, transparent)
}
/// The `<b>` element represents a span of text to which attention is being drawn for utilitarian purposes without conveying any extra importance and with no implication of an alternate voice or mood, such as key words in a document abstract, product names in a review, actionable words in interactive text-driven software, or an article lede.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func b(_ attribs: [Attribute<Tag.B>], _ content: [Node]) -> Node {
return element("b", attribs, content)
}
/// The `<b>` element represents a span of text to which attention is being drawn for utilitarian purposes without conveying any extra importance and with no implication of an alternate voice or mood, such as key words in a document abstract, product names in a review, actionable words in interactive text-driven software, or an article lede.
///
/// - Parameter content: Child nodes.
public func b(_ content: [Node]) -> Node {
return b([], content)
}
/// The `<base>` element allows authors to specify the document base URL for the purposes of parsing URLs, and the name of the default browsing context for the purposes of following hyperlinks. The element does not represent any content beyond this information.
///
/// - Parameters:
/// - attribs: Attributes.
public func base(_ attribs: [Attribute<Tag.Base>]) -> ChildOf<Tag.Head> {
return .init(element("base", attribs, []))
}
/// The `<bdi>` element represents a span of text that is to be isolated from its surroundings for the purposes of bidirectional text formatting.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func bdi(_ attribs: [Attribute<Tag.Bdi>], _ content: [Node]) -> Node {
return element("bdi", attribs, content)
}
/// The `<bdi>` element represents a span of text that is to be isolated from its surroundings for the purposes of bidirectional text formatting.
///
/// - Parameter content: Child nodes.
public func bdi(_ content: [Node]) -> Node {
return bdi([], content)
}
/// A sub-set of directions, valid for `<bdo>` elements.
public enum BdoDirection: String {
/// Left-to-right.
case ltr
/// Right-to-left.
case rtl
}
/// The `<bdo>` element represents explicit text directionality formatting control for its children. It allows authors to override the Unicode bidirectional algorithm by explicitly specifying a direction override.
///
/// - Parameters:
/// - dir: The element's text directionality.
/// - attribs: Attributes.
/// - content: Child nodes.
public func bdo(dir: BdoDirection, _ attribs: [Attribute<Tag.Bdi>], _ content: [Node]) -> Node {
return element("bdo", [.init("dir", dir.rawValue)] + attribs, content)
}
/// The `<bdo>` element represents explicit text directionality formatting control for its children. It allows authors to override the Unicode bidirectional algorithm by explicitly specifying a direction override.
///
/// - Parameters:
/// - dir: The element's text directionality.
/// - content: Child nodes.
public func bdo(dir: BdoDirection, _ content: [Node]) -> Node {
return bdo(dir: dir, [], content)
}
/// The `<blockquote>` element represents content that is quoted from another source, optionally with a citation which must be within a `<footer>` or `<cite>` element, and optionally with in-line changes such as annotations and abbreviations.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func blockquote(_ attribs: [Attribute<Tag.Blockquote>], _ content: [Node]) -> Node {
return element("blockquote", attribs, content)
}
/// The `<blockquote>` element represents content that is quoted from another source, optionally with a citation which must be within a `<footer>` or `<cite>` element, and optionally with in-line changes such as annotations and abbreviations.
///
/// - Parameter content: Child nodes.
public func blockquote(_ content: [Node]) -> Node {
return blockquote([], content)
}
/// The `<body>` element represents the content of the document.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func body(_ attribs: [Attribute<Tag.Body>], _ content: [Node]) -> ChildOf<Tag.Html> {
return .init(element("body", attribs, content))
}
/// The `<body>` element represents the content of the document.
///
/// - Parameter content: Child nodes.
public func body(_ content: [Node]) -> ChildOf<Tag.Html> {
return body([], content)
}
/// The `<br>` element represents a line break.
public let br: Node = element("br", [])
/// The `<button>` element represents a control allowing a user to trigger actions, when enabled. It is labeled by its content.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func button(_ attribs: [Attribute<Tag.Button>], _ content: [Node]) -> Node {
return element("button", attribs, content)
}
/// The `<button>` element represents a control allowing a user to trigger actions, when enabled. It is labeled by its content.
///
/// - Parameter content: Child nodes.
public func button(_ content: [Node]) -> Node {
return button([], content)
}
/// The `<canvas>` element provides scripts with a resolution-dependent bitmap canvas, which can be used for rendering graphs, game graphics, art, or other visual images on the fly.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func canvas(_ attribs: [Attribute<Tag.Canvas>], _ content: [Node]) -> Node {
return element("canvas", attribs, content)
}
/// The `<canvas>` element provides scripts with a resolution-dependent bitmap canvas, which can be used for rendering graphs, game graphics, art, or other visual images on the fly.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func canvas(_ content: [Node]) -> Node {
return canvas([], content)
}
// TODO: "caption" can only be the first element of a "table"
/// The `<caption>` element represents the title of the table that is its parent, if it has a parent and that is a table element.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func caption(_ attribs: [Attribute<Tag.Caption>], _ content: [Node]) -> ChildOf<Tag.Table> {
return .init(element("caption", attribs, content))
}
// TODO: "caption" can only be the first element of a "table"
/// The `<caption>` element represents the title of the table that is its parent, if it has a parent and that is a table element.
///
/// - Parameter content: Child nodes.
public func caption(_ content: [Node]) -> ChildOf<Tag.Table> {
return caption([], content)
}
/// The `<cite>` element represents a reference to a creative work. It must include the title of the work or the name of the author (person, people or organization) or an URL reference, or a reference in abbreviated form as per the conventions used for the addition of citation metadata.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func cite(_ attribs: [Attribute<Tag.Cite>], _ content: [Node]) -> Node {
return element("cite", attribs, content)
}
/// The `<cite>` element represents a reference to a creative work. It must include the title of the work or the name of the author (person, people or organization) or an URL reference, or a reference in abbreviated form as per the conventions used for the addition of citation metadata.
///
/// - Parameter content: Child nodes.
public func cite(_ content: [Node]) -> Node {
return cite([], content)
}
/// The `<code>` element represents a fragment of computer code. This could be an XML element name, a file name, a computer program, or any other string that a computer would recognize.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func code(_ attribs: [Attribute<Tag.Code>], _ content: [Node]) -> Node {
return element("code", attribs, content)
}
/// The `<code>` element represents a fragment of computer code. This could be an XML element name, a file name, a computer program, or any other string that a computer would recognize.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func code(_ content: [Node]) -> Node {
return code([], content)
}
/// If a `<col>` element has a parent and that is a `<colgroup>` element that itself has a parent that is a `<table>` element, then the `<col>` element represents one or more columns in the column group represented by that `<colgroup>`.
///
/// - Parameters:
/// - attribs: Attributes.
public func col(_ attribs: [Attribute<Tag.Col>]) -> ChildOf<Tag.Colgroup> {
return .init(element("col", attribs, []))
}
/// The `<colgroup>` element represents a group of one or more columns in the `table` that is its parent, if it has a parent and that is a `<table>` element.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func colgroup(_ attribs: [Attribute<Tag.Colgroup>], _ content: [ChildOf<Tag.Colgroup>])
-> ChildOf<Tag.Table> {
return .init(element("colgroup", attribs, content.map { $0.rawValue }))
}
/// The `<colgroup>` element represents a group of one or more columns in the `table` that is its parent, if it has a parent and that is a `<table>` element.
///
/// - Parameter content: Child nodes.
public func colgroup(_ content: [ChildOf<Tag.Colgroup>]) -> ChildOf<Tag.Table> {
return colgroup([], content)
}
/// The `<dd>` element represents a description, part of a term-description group in a description list (`<dl>` element).
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func dd(_ attribs: [Attribute<Tag.Dd>], _ content: [Node]) -> ChildOf<Tag.Dl> {
return .init(element("dd", attribs, content))
}
/// The `<dd>` element represents a description, part of a term-description group in a description list (`<dl>` element).
///
/// - Parameter content: Child nodes.
public func dd(_ content: [Node]) -> ChildOf<Tag.Dl> {
return dd([], content)
}
/// The `<del>` element represents a removal from the document.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func del(_ attribs: [Attribute<Tag.Del>], _ content: [Node]) -> Node {
return element("del", attribs, content)
}
/// The `<del>` element represents a removal from the document.
///
/// - Parameter content: Child nodes.
public func del(_ content: [Node]) -> Node {
return del([], content)
}
// TODO: required first child element "summary"
/// The `<details>` element represents a disclosure widget from which the user can obtain additional information or controls.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func details(_ attribs: [Attribute<Tag.Details>], _ content: [Node]) -> Node {
return element("details", attribs, content)
}
// TODO: required first child element "summary"
/// The `<details>` element represents a disclosure widget from which the user can obtain additional information or controls.
///
/// - Parameter content: Child nodes.
public func details(_ content: [Node]) -> Node {
return details([], content)
}
/// The `<dfn>` element represents the defining instance of a term. The term-description group, `<p>`, `<li>` or `<section>` element that is the nearest ancestor of the `<dfn>` element must also contain the definition(s) for the term given by the `<dfn>` element.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func dfn(_ attribs: [Attribute<Tag.Dfn>], _ content: [Node]) -> Node {
return element("dfn", attribs, content)
}
/// The `<dfn>` element represents the defining instance of a term. The term-description group, `<p>`, `<li>` or `<section>` element that is the nearest ancestor of the `<dfn>` element must also contain the definition(s) for the term given by the `<dfn>` element.
///
/// - Parameter content: Child nodes.
public func dfn(_ content: [Node]) -> Node {
return dfn([], content)
}
/// The `<div>` element has no special meaning at all. It represents its children. It can be used with the `class`, `lang`, and `title` attributes to mark up semantics common to a group of consecutive elements.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func div(_ attribs: [Attribute<Tag.Div>], _ content: [Node]) -> Node {
return element("div", attribs, content)
}
/// The `<div>` element has no special meaning at all. It represents its children.
///
/// - Parameter content: Child nodes.
public func div(_ content: [Node]) -> Node {
return div([], content)
}
/// The `<dl>` element represents a description list of zero or more term-description groups. Each term-description group consists of one or more terms (represented by `<dt>` elements) possibly as children of a `<div>` element child, and one or more descriptions (represented by `<dd>` elements possibly as children of a `<div>` element child), ignoring any nodes other than `<dt>` and `<dd>` element children, and `<dt>` and `<dd>` elements that are children of `<div>` element children within a single `<dl>` element.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func dl(_ attribs: [Attribute<Tag.Dl>], _ content: [ChildOf<Tag.Dl>]) -> Node {
return element("dl", attribs, content.map { $0.rawValue })
}
/// The `<dl>` element represents a description list of zero or more term-description groups. Each term-description group consists of one or more terms (represented by `<dt>` elements) possibly as children of a `<div>` element child, and one or more descriptions (represented by `<dd>` elements possibly as children of a `<div>` element child), ignoring any nodes other than `<dt>` and `<dd>` element children, and `<dt>` and `<dd>` elements that are children of `<div>` element children within a single `<dl>` element.
///
/// - Parameter content: Child nodes.
public func dl(_ content: [ChildOf<Tag.Dl>]) -> Node {
return dl([], content)
}
/// The `<dt>` element represents a term, part of a term-description group in a description list (`<dl>` element).
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func dt(_ attribs: [Attribute<Tag.Dt>], _ content: [Node]) -> ChildOf<Tag.Dl> {
return .init(element("dt", attribs, content))
}
/// The `<dt>` element represents a term, part of a term-description group in a description list (`<dl>` element).
///
/// - Parameter content: Child nodes.
public func dt(_ content: [Node]) -> ChildOf<Tag.Dl> {
return dt([], content)
}
/// The `<em>` element represents stress emphasis of its contents.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func em(_ attribs: [Attribute<Tag.Em>], _ content: [Node]) -> Node {
return element("em", attribs, content)
}
/// The `<em>` element represents stress emphasis of its contents.
///
/// - Parameter content: Child nodes.
public func em(_ content: [Node]) -> Node {
return em([], content)
}
/// The `<embed>` element provides an integration point for an external (typically non-HTML) application or interactive content.
///
/// - Parameter attribs: Attributes.
public func embed(_ attribs: [Attribute<Tag.Embed>]) -> Node {
return element("embed", attribs, [])
}
/// The `<fieldset>` element represents a set of form controls optionally grouped under a common name.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func fieldset(_ attribs: [Attribute<Tag.Fieldset>], _ content: [Node]) -> Node {
return element("fieldset", attribs, content)
}
/// The `<fieldset>` element represents a set of form controls optionally grouped under a common name.
///
/// - Parameter content: Child nodes.
public func fieldset(_ content: [Node]) -> Node {
return fieldset([], content)
}
/// The `<figcaption>` element represents a caption or legend for the rest of the contents of the `<figcaption>` element's parent `<figure>` element, if any.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func figcaption(_ attribs: [Attribute<Tag.Figcaption>], _ content: [Node])
-> ChildOf<Tag.Figure> {
return .init(element("figcaption", attribs, content))
}
/// The `<figcaption>` element represents a caption or legend for the rest of the contents of the `<figcaption>` element's parent `<figure>` element, if any.
///
/// - Parameter content: Child nodes.
public func figcaption(_ content: [Node]) -> ChildOf<Tag.Figure> {
return figcaption([], content)
}
/// The `<figure>` element represents some flow content, optionally with a caption, that is self-contained (like a complete sentence) and is typically referenced as a single unit from the main flow of the document.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func figure(_ attribs: [Attribute<Tag.Figure>], _ content: [ChildOf<Tag.Figure>]) -> Node {
return element("figure", attribs, content.map { $0.rawValue })
}
/// The `<figure>` element represents some flow content, optionally with a caption, that is self-contained (like a complete sentence) and is typically referenced as a single unit from the main flow of the document.
///
/// - Parameter content: Child nodes.
public func figure(_ content: [ChildOf<Tag.Figure>]) -> Node {
return figure([], content)
}
/// The `<footer>` element represents a footer for its nearest ancestor `<main>` element or sectioning content or sectioning root element. A footer typically contains information about its section, such as who wrote it, links to related documents, copyright data, and the like.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func footer(_ attribs: [Attribute<Tag.Footer>], _ content: [Node]) -> Node {
return element("footer", attribs, content)
}
/// The `<footer>` element represents a footer for its nearest ancestor `<main>` element or sectioning content or sectioning root element. A footer typically contains information about its section, such as who wrote it, links to related documents, copyright data, and the like.
///
/// - Parameter content: Child nodes.
public func footer(_ content: [Node]) -> Node {
return footer([], content)
}
/// The `<form>` element represents a collection of form-associated elements, some of which can represent editable values that can be submitted to a server for processing.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func form(_ attribs: [Attribute<Tag.Form>], _ content: [Node]) -> Node {
return element("form", attribs, content)
}
/// The `<form>` element represents a collection of form-associated elements, some of which can represent editable values that can be submitted to a server for processing.
///
/// - Parameter content: Child nodes.
public func form(_ content: [Node]) -> Node {
return form([], content)
}
/// These elements represent headings for their sections. The `<h1>` element has the highest rank.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func h1(_ attribs: [Attribute<Tag.H1>], _ content: [Node]) -> Node {
return element("h1", attribs, content)
}
/// These elements represent headings for their sections. The `<h1>` element has the highest rank.
///
/// - Parameter content: Child nodes.
public func h1(_ content: [Node]) -> Node {
return h1([], content)
}
/// These elements represent headings for their sections. The `<h2>` element has the second-highest rank.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func h2(_ attribs: [Attribute<Tag.H2>], _ content: [Node]) -> Node {
return element("h2", attribs, content)
}
/// These elements represent headings for their sections. The `<h2>` element has the second-highest rank.
///
/// - Parameter content: Child nodes.
public func h2(_ content: [Node]) -> Node {
return h2([], content)
}
/// These elements represent headings for their sections. The `<h3>` element has the third-highest rank.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func h3(_ attribs: [Attribute<Tag.H3>], _ content: [Node]) -> Node {
return element("h3", attribs, content)
}
/// These elements represent headings for their sections. The `<h3>` element has the third-highest rank.
///
/// - Parameter content: Child nodes.
public func h3(_ content: [Node]) -> Node {
return h3([], content)
}
/// These elements represent headings for their sections. The `<h4>` element has the fourth-highest rank.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func h4(_ attribs: [Attribute<Tag.H4>], _ content: [Node]) -> Node {
return element("h4", attribs, content)
}
/// These elements represent headings for their sections. The `<h4>` element has the fourth-highest rank.
///
/// - Parameter content: Child nodes.
public func h4(_ content: [Node]) -> Node {
return h4([], content)
}
/// These elements represent headings for their sections. The `<h5>` element has the fifth-highest rank.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func h5(_ attribs: [Attribute<Tag.H5>], _ content: [Node]) -> Node {
return element("h5", attribs, content)
}
/// These elements represent headings for their sections. The `<h5>` element has the fifth-highest rank.
///
/// - Parameter content: Child nodes.
public func h5(_ content: [Node]) -> Node {
return h5([], content)
}
/// These elements represent headings for their sections. The `<h6>` element has the lowest rank.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func h6(_ attribs: [Attribute<Tag.H6>], _ content: [Node]) -> Node {
return element("h6", attribs, content)
}
/// These elements represent headings for their sections. The `<h6>` element has the lowest rank.
///
/// - Parameter content: Child nodes.
public func h6(_ content: [Node]) -> Node {
return h6([], content)
}
/// The `<head> element represents a collection of metadata for the `Document`.
///
/// - Parameter content: Child nodes.
public func head(_ content: [ChildOf<Tag.Head>]) -> ChildOf<Tag.Html> {
return .init(element("head", content.map { $0.rawValue }))
}
/// The `<head> element represents a collection of metadata for the `Document`.
///
/// - Parameter content: Child nodes.
///
/// - Parameters:
/// - title: Content for the `<title>` element.
/// - content: Child nodes.
public func head(title: String, content: [ChildOf<Tag.Head>] = []) -> ChildOf<Tag.Html> {
return head([Html.title(title)] + content)
}
/// The `<header>` element represents introductory content for its nearest ancestor `<main>` element or sectioning content or sectioning root element. A `<header>` typically contains a group of introductory or navigational aids.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func header(_ attribs: [Attribute<Tag.Header>], _ content: [Node]) -> Node {
return element("header", attribs, content)
}
/// The `<header>` element represents introductory content for its nearest ancestor `<main>` element or sectioning content or sectioning root element. A `<header>` typically contains a group of introductory or navigational aids.
///
/// - Parameter content: Child nodes.
public func header(_ content: [Node]) -> Node {
return header([], content)
}
/// The `<hr>` element represents a paragraph-level thematic break, e.g., a scene change in a story, or a transition to another topic within a section of a reference book.
public let hr: Node = element("hr", [])
/// The `<hr>` element represents a paragraph-level thematic break, e.g., a scene change in a story, or a transition to another topic within a section of a reference book.
///
/// - Parameter attribs: Attributes.
public func hr(_ attribs: [Attribute<Tag.Hr>]) -> Node {
return element("hr", attribs, [])
}
/// The `<html>` element represents the root of an HTML document.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func html(_ attribs: [Attribute<Tag.Html>], _ content: [ChildOf<Tag.Html>]) -> Node {
return element("html", attribs, content.map { $0.rawValue })
}
/// The `<html>` element represents the root of an HTML document.
///
/// - Parameter content: Child nodes.
public func html(_ content: [ChildOf<Tag.Html>]) -> Node {
return html([], content)
}
/// The `<i>` element represents a span of text in an alternate voice or mood, or otherwise offset from the normal prose in a manner indicating a different quality of text, such as a taxonomic designation, a technical term, an idiomatic phrase from another language, transliteration, a thought, or a ship name in Western texts.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func i(_ attribs: [Attribute<Tag.I>], _ content: [Node]) -> Node {
return element("i", attribs, content)
}
/// The `<i>` element represents a span of text in an alternate voice or mood, or otherwise offset from the normal prose in a manner indicating a different quality of text, such as a taxonomic designation, a technical term, an idiomatic phrase from another language, transliteration, a thought, or a ship name in Western texts.
///
/// - Parameter content: Child nodes.
public func i(_ content: [Node]) -> Node {
return i([], content)
}
/// The `<iframe>` element represents a nested browsing context.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func iframe(_ attribs: [Attribute<Tag.Iframe>], _ content: [Node] = []) -> Node {
return element("iframe", attribs, content)
}
/// An `<img>` element represents an image and its fallback content.
///
/// - Parameter attribs: An array of attributes.
public func img(_ attribs: [Attribute<Tag.Img>]) -> Node {
return element("img", attribs, [])
}
/// An `<img>` element represents an image and its fallback content.
///
/// - Parameters:
/// - src: Address of the resource.
/// - alt: Replacement text for use when images are not available.
/// - attribs: Additional attributes.
public func img(src: String, alt: String, _ attribs: [Attribute<Tag.Img>] = []) -> Node {
return img([Html.src(src), Html.alt(alt)] + attribs)
}
/// An `<img>` element represents an image and its fallback content.
///
/// - Parameters:
/// - base64: A base64-encoded image.
/// - type: The image's content encoding.
/// - alt: Replacement text for use when images are not available.
/// - attribs: Additional attributes.
public func img(base64: String, type: MediaType, alt: String, _ attribs: [Attribute<Tag.Img>])
-> Node {
return img(src: "data:\(type.description);base64,\(base64)", alt: alt, attribs)
}
/// The `<input>` element represents a typed data field, usually with a form control to allow the user to edit the data.
///
/// - Parameter attribs: Attributes.
public func input(_ attribs: [Attribute<Tag.Input>]) -> Node {
return element("input", attribs, [])
}
/// The `<ins>` element represents an addition to the document.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func ins(_ attribs: [Attribute<Tag.Ins>], _ content: [Node]) -> Node {
return element("ins", attribs, content)
}
/// The `<ins>` element represents an addition to the document.
///
/// - Parameter content: Child nodes.
public func ins(_ content: [Node]) -> Node {
return ins([], content)
}
/// The `<kbd>` element represents user input (typically keyboard input, although it may also be used to represent other input, such as voice commands).
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func kbd(_ attribs: [Attribute<Tag.Kbd>], _ content: [Node]) -> Node {
return element("kbd", attribs, content)
}
/// The `<kbd>` element represents user input (typically keyboard input, although it may also be used to represent other input, such as voice commands).
///
/// - Parameter content: Child nodes.
public func kbd(_ content: [Node]) -> Node {
return kbd([], content)
}
/// The `<label>` element represents a caption in a user interface. The caption can be associated with a specific form control, known as the `<label>` element's **labeled control**, either using the `for` attribute, or by putting the form control inside the `<label>` element itself.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func label(_ attribs: [Attribute<Tag.Label>], _ content: [Node]) -> Node {
return element("label", attribs, content)
}
/// The `<label>` element represents a caption in a user interface. The caption can be associated with a specific form control, known as the `<label>` element's **labeled control**, either using the `for` attribute, or by putting the form control inside the `<label>` element itself.
///
/// - Parameter content: Child nodes.
public func label(_ content: [Node]) -> Node {
return label([], content)
}
/// The `<legend>` element represents a caption for the rest of the contents of the `<legend>` element's parent `<fieldset>` element, if any.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func legend(_ attribs: [Attribute<Tag.Legend>], _ content: [Node]) -> ChildOf<Tag.Fieldset> {
return .init(element("legend", attribs, content))
}
/// The `<legend>` element represents a caption for the rest of the contents of the `<legend>` element's parent `<fieldset>` element, if any.
///
/// - Parameter content: Child nodes.
public func legend(_ content: [Node]) -> ChildOf<Tag.Fieldset> {
return legend([], content)
}
/// Conforming elements can contain `<li>` elements. Includes `<ol>` and `<ul>` elements.
public protocol ContainsLi {}
extension Tag.Ol: ContainsLi {}
extension Tag.Ul: ContainsLi {}
/// The `<li>` element represents a list item. If its parent element is an `<ol>`, or `<ul>`, then the element is an item of the parent element's list, as defined for those elements. Otherwise, the list item has no defined list-related relationship to any other `<li>` element.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func li<T: ContainsLi>(_ attribs: [Attribute<Tag.Li>], _ content: [Node]) -> ChildOf<T> {
return .init(element("li", attribs, content))
}
/// The `<li>` element represents a list item. If its parent element is an `<ol>`, or `<ul>`, then the element is an item of the parent element's list, as defined for those elements. Otherwise, the list item has no defined list-related relationship to any other `<li>` element.
///
/// - Parameter content: Child nodes.
public func li<T: ContainsLi>(_ content: [Node]) -> ChildOf<T> {
return li([], content)
}
/// The `<link>` element allows authors to link their document to other resources.
///
/// - Parameter attribs: Attributes.
public func link(_ attribs: [Attribute<Tag.Link>]) -> ChildOf<Tag.Head> {
return .init(element("link", attribs, []))
}
/// The `<main>` element represents the main content of the `<body>` of a document or application.
///
/// - Parameters:
/// - attribs: Attributes.
/// - content: Child nodes.
public func main(_ attribs: [Attribute<Tag.Main>], _ content: [Node]) -> Node {
return element("main", attribs, content)
}
/// The `<main>` element represents the main content of the `<body>` of a document or application.
///
/// - Parameter content: Child nodes.
public func main(_ content: [Node]) -> Node {
return main([], content)
}
/// The `<map>` element, in conjunction with an `<img>` element and any `<area>` element descendants, defines an image map. The element represents its children.
///
/// - Parameters:
/// - name: The `name` attribute gives the map a name so that it can be referenced. The attribute must be present and must have a non-empty value with no space characters. The value of the `name` attribute must not be a compatibility caseless match for the value of the `name` attribute of another `<map>` element in the same document. If the `id` attribute is also specified, both attributes must have the same value.
/// - attribs: Additional attributes.
/// - content: Child nodes.
public func map(name: String, _ attribs: [Attribute<Tag.Map>], _ content: [ChildOf<Tag.Map>])
-> Node {