forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlScripts.cs
More file actions
669 lines (556 loc) · 29.6 KB
/
HtmlScripts.cs
File metadata and controls
669 lines (556 loc) · 29.6 KB
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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceStack.Script;
using ServiceStack.Text;
namespace ServiceStack.Script
{
// ReSharper disable InconsistentNaming
public class HtmlScripts : ScriptMethods
{
public IRawString htmlList(IEnumerable target) => HtmlList(target, new HtmlDumpOptions { Defaults = Context.DefaultMethods }).ToRawString();
public IRawString htmlList(IEnumerable target, Dictionary<string, object> options) =>
HtmlList(target, HtmlDumpOptions.Parse(options, Context.DefaultMethods)).ToRawString();
public IRawString htmlDump(object target) => HtmlDump(target, new HtmlDumpOptions { Defaults = Context.DefaultMethods }).ToRawString();
public IRawString htmlDump(object target, Dictionary<string, object> options) =>
HtmlDump(target, HtmlDumpOptions.Parse(options, Context.DefaultMethods)).ToRawString();
public static string HtmlList(IEnumerable items, HtmlDumpOptions options)
{
if (options == null)
options = new HtmlDumpOptions();
if (items is IDictionary<string, object> single)
items = new[] { single };
var depth = options.Depth;
var childDepth = options.ChildDepth;
options.Depth += 1;
try
{
var parentClass = options.ClassName;
var childClass = options.ChildClass;
var className = ((depth < childDepth ? parentClass : childClass ?? parentClass)
?? options.Defaults.GetDefaultTableClassName());
var headerStyle = options.HeaderStyle;
var headerTag = options.HeaderTag ?? "th";
var sbHeader = StringBuilderCache.Allocate();
var sbRows = StringBuilderCacheAlt.Allocate();
List<string> keys = null;
foreach (var item in items)
{
if (item is IDictionary<string, object> d)
{
if (keys == null)
{
keys = d.Keys.ToList();
sbHeader.Append("<tr>");
foreach (var key in keys)
{
sbHeader.Append('<').Append(headerTag).Append('>');
sbHeader.Append(ViewUtils.StyleText(key, headerStyle)?.HtmlEncode());
sbHeader.Append("</").Append(headerTag).Append('>');
}
sbHeader.Append("</tr>");
}
sbRows.Append("<tr>");
foreach (var key in keys)
{
var value = d[key];
if (ReferenceEquals(value, items))
break; // Prevent cyclical deps like 'it' binding
sbRows.Append("<td>");
if (!isComplexType(value))
{
sbRows.Append(GetScalarHtml(value, options.Defaults));
}
else
{
var htmlValue = HtmlDump(value, options);
sbRows.Append(htmlValue.ToRawString());
}
sbRows.Append("</td>");
}
sbRows.Append("</tr>");
}
}
var isEmpty = sbRows.Length == 0;
if (isEmpty && options.CaptionIfEmpty == null)
return string.Empty;
var htmlHeaders = StringBuilderCache.ReturnAndFree(sbHeader);
var htmlRows = StringBuilderCacheAlt.ReturnAndFree(sbRows);
var sb = StringBuilderCache.Allocate();
sb.Append("<table");
if (options.Id != null)
sb.Append(" id=\"").Append(options.Id).Append("\"");
if (!string.IsNullOrEmpty(className))
sb.Append(" class=\"").Append(className).Append("\"");
sb.Append(">");
var caption = options.Caption;
if (isEmpty)
caption = options.CaptionIfEmpty;
if (caption != null && !options.HasCaption)
{
sb.Append("<caption>").Append(caption.HtmlEncode()).Append("</caption>");
options.HasCaption = true;
}
if (htmlHeaders.Length > 0)
sb.Append("<thead>").Append(htmlHeaders).Append("</thead>");
if (htmlRows.Length > 0)
sb.Append("<tbody>").Append(htmlRows).Append("</tbody>");
sb.Append("</table>");
var html = StringBuilderCache.ReturnAndFree(sb);
return html;
}
finally
{
options.Depth = depth;
}
}
public static string HtmlDump(object target, HtmlDumpOptions options)
{
if (options == null)
options = new HtmlDumpOptions();
var depth = options.Depth;
var childDepth = options.ChildDepth;
options.Depth += 1;
try
{
target = DefaultScripts.ConvertDumpType(target);
if (!isComplexType(target))
return GetScalarHtml(target, options.Defaults);
var parentClass = options.ClassName;
var childClass = options.ChildClass;
var className = ((depth < childDepth ? parentClass : childClass ?? parentClass)
?? options.Defaults.GetDefaultTableClassName());
var headerStyle = options.HeaderStyle;
var headerTag = options.HeaderTag ?? "th";
if (target is IEnumerable e)
{
var objs = e.Map(x => x);
var isEmpty = objs.Count == 0;
if (isEmpty && options.CaptionIfEmpty == null)
return string.Empty;
var first = !isEmpty ? objs[0] : null;
if (first is IDictionary && objs.Count > 1)
return HtmlList(objs, options);
var sb = StringBuilderCacheAlt.Allocate();
sb.Append("<table");
if (options.Id != null)
sb.Append(" id=\"").Append(options.Id).Append("\"");
if (!string.IsNullOrEmpty(className))
sb.Append(" class=\"").Append(className).Append("\"");
sb.Append(">");
var caption = options.Caption;
if (isEmpty)
caption = options.CaptionIfEmpty;
var holdCaption = options.HasCaption;
if (caption != null && !options.HasCaption)
{
sb.Append("<caption>").Append(caption.HtmlEncode()).Append("</caption>");
options.HasCaption = true;
}
if (!isEmpty)
{
sb.Append("<tbody>");
if (first is KeyValuePair<string, object>)
{
foreach (var o in objs)
{
if (o is KeyValuePair<string, object> kvp)
{
if (kvp.Value == target) break; // Prevent cyclical deps like 'it' binding
sb.Append("<tr>");
sb.Append('<').Append(headerTag).Append('>');
sb.Append(ViewUtils.StyleText(kvp.Key, headerStyle)?.HtmlEncode());
sb.Append("</").Append(headerTag).Append('>');
sb.Append("<td>");
if (!isComplexType(kvp.Value))
{
sb.Append(GetScalarHtml(kvp.Value, options.Defaults));
}
else
{
var body = HtmlDump(kvp.Value, options);
sb.Append(body.ToRawString());
}
sb.Append("</td>");
sb.Append("</tr>");
}
}
}
else if (!isComplexType(first))
{
foreach (var o in objs)
{
sb.Append("<tr>");
sb.Append("<td>");
sb.Append(GetScalarHtml(o, options.Defaults));
sb.Append("</td>");
sb.Append("</tr>");
}
}
else
{
if (objs.Count > 1)
{
var rows = objs.Map(x => x.ToObjectDictionary());
StringBuilderCache.Free(sb);
options.HasCaption = holdCaption;
return HtmlList(rows, options);
}
else
{
foreach (var o in objs)
{
sb.Append("<tr>");
if (!isComplexType(o))
{
sb.Append("<td>");
sb.Append(GetScalarHtml(o, options.Defaults));
sb.Append("</td>");
}
else
{
sb.Append("<td>");
var body = HtmlDump(o, options);
sb.Append(body.ToRawString());
sb.Append("</td>");
}
sb.Append("</tr>");
}
}
}
sb.Append("</tbody>");
}
sb.Append("</table>");
var html = StringBuilderCacheAlt.ReturnAndFree(sb);
return html;
}
return HtmlDump(target.ToObjectDictionary(), options);
}
finally
{
options.Depth = depth;
}
}
private static string GetScalarHtml(object target, DefaultScripts defaults)
{
if (target == null || target.ToString() == string.Empty)
return string.Empty;
if (target is string s)
return s.HtmlEncode();
if (target is decimal dec)
{
var isMoney = dec == Math.Floor(dec * 100);
if (isMoney)
return defaults?.currency(dec) ?? dec.ToString(defaults.GetDefaultCulture());
}
if (target.GetType().IsNumericType() || target is bool)
return target.ToString();
if (target is DateTime d)
return defaults?.dateFormat(d) ?? d.ToString(defaults.GetDefaultCulture());
if (target is TimeSpan t)
return defaults?.timeFormat(t) ?? t.ToString();
return (target.ToString() ?? "").HtmlEncode();
}
private static bool isComplexType(object first)
{
return !(first == null || first is string || first.GetType().IsValueType);
}
public IRawString htmlError(ScriptScopeContext scope) => htmlError(scope, scope.PageResult.LastFilterError);
public IRawString htmlError(ScriptScopeContext scope, Exception ex) => htmlError(scope, ex, null);
public IRawString htmlError(ScriptScopeContext scope, Exception ex, object options) =>
Context.DebugMode ? htmlErrorDebug(scope, ex, options) : htmlErrorMessage(ex, options);
public IRawString htmlErrorMessage(ScriptScopeContext scope) => htmlErrorMessage(scope.PageResult.LastFilterError);
public IRawString htmlErrorMessage(Exception ex) => htmlErrorMessage(ex, null);
public IRawString htmlErrorMessage(Exception ex, object options)
{
if (ex == null)
return RawString.Empty;
var scopedParams = options as Dictionary<string, object> ?? TypeConstants.EmptyObjectDictionary;
var className = (scopedParams.TryGetValue("className", out object oClassName) ? oClassName : null)
?? Context.Args[ScriptConstants.DefaultErrorClassName];
return $"<div class=\"{className}\">{ex.Message}</div>".ToRawString();
}
public IRawString htmlErrorDebug(ScriptScopeContext scope) => htmlErrorDebug(scope, scope.PageResult.LastFilterError);
public IRawString htmlErrorDebug(ScriptScopeContext scope, object ex) =>
htmlErrorDebug(scope, ex as Exception ?? scope.PageResult.LastFilterError, ex as Dictionary<string, object>);
public IRawString htmlErrorDebug(ScriptScopeContext scope, Exception ex, object options)
{
if (ex == null)
return RawString.Empty;
var scopedParams = options as Dictionary<string, object> ?? TypeConstants.EmptyObjectDictionary;
var className = (scopedParams.TryGetValue("className", out object oClassName) ? oClassName : null)
?? Context.Args[ScriptConstants.DefaultErrorClassName];
var sb = StringBuilderCache.Allocate();
sb.Append($"<pre class=\"{className}\">");
sb.AppendLine($"{ex.GetType().Name}: {ex.Message}");
var stackTrace = scope.Context.DefaultMethods.lastErrorStackTrace(scope);
if (!string.IsNullOrEmpty(stackTrace))
{
sb.AppendLine();
sb.AppendLine("StackTrace:");
sb.AppendLine(stackTrace);
}
else if (!string.IsNullOrEmpty(ex.StackTrace))
{
sb.AppendLine();
sb.AppendLine("StackTrace:");
sb.AppendLine(ex.StackTrace);
}
if (ex.InnerException != null)
{
sb.AppendLine();
sb.AppendLine("Inner Exceptions:");
var innerEx = ex.InnerException;
while (innerEx != null)
{
sb.AppendLine($"{innerEx.GetType().Name}: {innerEx.Message}");
if (!string.IsNullOrEmpty(innerEx.StackTrace))
sb.AppendLine(innerEx.StackTrace);
innerEx = innerEx.InnerException;
}
}
sb.AppendLine("</pre>");
var html = StringBuilderCache.ReturnAndFree(sb);
return html.ToRawString();
}
public string htmlAttrsList(Dictionary<string, object> attrs)
{
if (attrs == null || attrs.Count == 0)
return string.Empty;
var sb = StringBuilderCache.Allocate();
var keys = attrs.Keys.OrderBy(x => x);
foreach (var key in keys)
{
if (key == "text" || key == "html")
continue;
var value = attrs[key];
if (ViewUtils.IsNull(value))
continue;
var useKey = key == "className"
? "class"
: key == "htmlFor"
? "for"
: key;
if (value is bool boolAttr)
{
if (boolAttr) // only emit attr name if value == true
{
sb.Append(' ').Append(useKey);
}
}
else
{
sb.Append(' ').Append(useKey).Append('=').Append('"').Append(value?.ToString().HtmlEncode()).Append('"');
}
}
return sb.ToString();
}
public IRawString htmlAttrs(object target)
{
var attrs = htmlAttrsList(target as Dictionary<string, object>);
return (attrs.Length > 0 ? attrs : "").ToRawString();
}
public string htmlClassList(object target)
{
if (target == null)
return null;
if (target is string clsName)
return clsName;
var sb = StringBuilderCache.Allocate();
if (target is Dictionary<string, object> flags)
{
foreach (var entry in flags)
{
if (entry.Value is bool b && b)
{
if (sb.Length > 0)
sb.Append(" ");
sb.Append(entry.Key);
}
}
}
else if (target is List<object> list)
{
foreach (var item in list)
{
if (item is string str && str.Length > 0)
{
if (sb.Length > 0)
sb.Append(" ");
sb.Append(str);
}
}
}
else if (target != null)
{
throw new NotSupportedException($"{nameof(htmlClass)} expects a Dictionary, List or String argument but was '{target.GetType().Name}'");
}
return StringBuilderCache.ReturnAndFree(sb);
}
public IRawString htmlClass(object target)
{
var cls = htmlClassList(target);
return (cls.Length > 0 ? $" class=\"{cls}\"" : "").ToRawString();
}
public bool htmlHasClass(object target, string name)
{
if (target == null)
return false;
if (target is Dictionary<string, object> flags)
return flags.TryGetValue(name, out var oFlags) && oFlags is bool flag && flag;
if (target is List<object> list)
{
foreach (var oCls in list)
{
if (oCls is string cls && cls == name)
return true;
}
return false;
}
if (target is string className)
return ($" {className} ").IndexOf($" {name} ", StringComparison.Ordinal) >= 0;
return false;
}
public string htmlAddClass(object target, string name)
{
var className = htmlClassList(target) ?? "";
if (htmlHasClass(target, name))
return className;
return className + " " + name;
}
public IRawString htmlFormat(string htmlWithFormat, string arg)
{
if (string.IsNullOrEmpty(arg))
return null;
return string.Format(htmlWithFormat, Context.DefaultMethods.htmlEncode(arg)).ToRawString();
}
public IRawString htmlLink(string href) => htmlLink(href, new Dictionary<string, object> { ["text"] = href });
public IRawString htmlLink(string href, Dictionary<string, object> attrs)
{
if (string.IsNullOrEmpty(href))
return RawString.Empty;
return htmlA(new Dictionary<string, object>(attrs ?? TypeConstants.EmptyObjectDictionary) { ["href"] = href });
}
public IRawString htmlImage(string src) => htmlImage(src, null);
public IRawString htmlImage(string src, Dictionary<string, object> attrs)
{
if (string.IsNullOrEmpty(src))
return RawString.Empty;
return htmlImg(new Dictionary<string, object>(attrs ?? TypeConstants.EmptyObjectDictionary) { ["src"] = src });
}
public IRawString htmlHiddenInputs(Dictionary<string, object> inputValues) =>
ViewUtils.HtmlHiddenInputs(inputValues).ToRawString();
public IRawString htmlOptions(object values) => htmlOptions(values, null);
public IRawString htmlOptions(object values, object options)
{
if (values == null)
return RawString.Empty;
var opt = options.AssertOptions(nameof(htmlOptions));
var selected = opt.TryGetValue("selected", out var oSelected) ? oSelected as string : null;
var sb = StringBuilderCache.Allocate();
void appendOption(StringBuilder _sb, string value, string text)
{
var selAttr = selected != null && value == selected ? " selected" : "";
_sb.AppendLine($"<option value=\"{value.HtmlEncode()}\"{selAttr}>{text?.HtmlEncode()}</option>");
}
if (values is IEnumerable<KeyValuePair<string, object>> kvps)
{
foreach (var kvp in kvps) appendOption(sb, kvp.Key, kvp.Value?.ToString());
}
else if (values is IEnumerable<KeyValuePair<string, string>> kvpsStr)
{
foreach (var kvp in kvpsStr) appendOption(sb, kvp.Key, kvp.Value);
}
else if (values is IEnumerable<object> list)
{
foreach (string item in list)
{
var str = item.AsString();
var selAttr = selected != null && str == selected ? " selected" : "";
sb.AppendLine($"<option{selAttr}>{str?.HtmlEncode()}</option>");
}
}
else throw new NotSupportedException($"Could not convert '{values.GetType().Name}' values into List<string>");
return StringBuilderCache.ReturnAndFree(sb).ToRawString();
}
public static HashSet<string> VoidElements { get; } = new HashSet<string>
{
"area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"
};
public IRawString htmlTag(Dictionary<string, object> attrs, string tag)
{
var scopedParams = attrs ?? TypeConstants.EmptyObjectDictionary;
var innerHtml = scopedParams.TryGetValue("html", out object oInnerHtml)
? oInnerHtml.AsString()
: null;
if (innerHtml == null)
{
innerHtml = scopedParams.TryGetValue("text", out object text)
? text.AsString().HtmlEncode()
: null;
}
var attrString = htmlAttrsList(attrs);
return VoidElements.Contains(tag)
? $"<{tag}{attrString}>".ToRawString()
: $"<{tag}{attrString}>{innerHtml}</{tag}>".ToRawString();
}
public IRawString htmlTag(string innerHtml, Dictionary<string, object> attrs, string tag)
{
return htmlTag(new Dictionary<string, object>(attrs ?? TypeConstants.EmptyObjectDictionary) { ["html"] = innerHtml }, tag);
}
public IRawString htmlDiv(Dictionary<string, object> attrs) => htmlTag(attrs, "div");
public IRawString htmlDiv(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "div");
public IRawString htmlSpan(Dictionary<string, object> attrs) => htmlTag(attrs, "span");
public IRawString htmlSpan(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "span");
public IRawString htmlA(Dictionary<string, object> attrs) => htmlTag(attrs, "a");
public IRawString htmlA(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "a");
public IRawString htmlImg(Dictionary<string, object> attrs) => htmlTag(attrs, "img");
public IRawString htmlImg(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "img");
public IRawString htmlH1(Dictionary<string, object> attrs) => htmlTag(attrs, "h1");
public IRawString htmlH1(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "h1");
public IRawString htmlH2(Dictionary<string, object> attrs) => htmlTag(attrs, "h2");
public IRawString htmlH2(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "h2");
public IRawString htmlH3(Dictionary<string, object> attrs) => htmlTag(attrs, "h3");
public IRawString htmlH3(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "h3");
public IRawString htmlH4(Dictionary<string, object> attrs) => htmlTag(attrs, "h4");
public IRawString htmlH4(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "h4");
public IRawString htmlH5(Dictionary<string, object> attrs) => htmlTag(attrs, "h5");
public IRawString htmlH5(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "h5");
public IRawString htmlH6(Dictionary<string, object> attrs) => htmlTag(attrs, "h6");
public IRawString htmlH6(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "h6");
public IRawString htmlEm(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "em");
public IRawString htmlEm(string text) => htmlTag(new Dictionary<string, object>{ ["text"] = text }, "em");
public IRawString htmlB(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "b");
public IRawString htmlB(string text) => htmlTag(new Dictionary<string, object>{ ["text"] = text }, "b");
public IRawString htmlUl(Dictionary<string, object> attrs) => htmlTag(attrs, "ul");
public IRawString htmlUl(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "ul");
public IRawString htmlOl(Dictionary<string, object> attrs) => htmlTag(attrs, "ol");
public IRawString htmlOl(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "ol");
public IRawString htmlLi(Dictionary<string, object> attrs) => htmlTag(attrs, "li");
public IRawString htmlLi(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "li");
public IRawString htmlTable(Dictionary<string, object> attrs) => htmlTag(attrs, "table");
public IRawString htmlTable(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "table");
public IRawString htmlTr(Dictionary<string, object> attrs) => htmlTag(attrs, "tr");
public IRawString htmlTr(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "tr");
public IRawString htmlTh(Dictionary<string, object> attrs) => htmlTag(attrs, "th");
public IRawString htmlTh(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "th");
public IRawString htmlTd(Dictionary<string, object> attrs) => htmlTag(attrs, "td");
public IRawString htmlTd(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "td");
public IRawString htmlForm(Dictionary<string, object> attrs) => htmlTag(attrs, "form");
public IRawString htmlForm(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "form");
public IRawString htmlLabel(Dictionary<string, object> attrs) => htmlTag(attrs, "label");
public IRawString htmlLabel(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "label");
public IRawString htmlInput(Dictionary<string, object> attrs) => htmlTag(attrs, "input");
public IRawString htmlInput(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "input");
public IRawString htmlTextArea(Dictionary<string, object> attrs) => htmlTag(attrs, "textarea");
public IRawString htmlTextArea(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "textarea");
public IRawString htmlButton(Dictionary<string, object> attrs) => htmlTag(attrs, "button");
public IRawString htmlButton(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "button");
public IRawString htmlSelect(Dictionary<string, object> attrs) => htmlTag(attrs, "select");
public IRawString htmlSelect(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "select");
public IRawString htmlOption(string innerHtml, Dictionary<string, object> attrs) => htmlTag(innerHtml, attrs, "option");
public IRawString htmlOption(string text) => htmlTag(new Dictionary<string, object>{ ["text"] = text }, "option");
}
}