@@ -622,6 +622,27 @@ HTML.flattenAttributes = function (attrs) {
622
622
623
623
////////////////////////////// TOHTML
624
624
625
+ /**
626
+ * ## HTML.toHTML(content)
627
+ *
628
+ * * `content` - any HTMLjs content
629
+ *
630
+ * Returns a string of HTML generated from `content`.
631
+ *
632
+ * For example:
633
+ *
634
+ * ```
635
+ * HTML.toHTML(HTML.HR()) // => "<hr>"
636
+ * ```
637
+ *
638
+ * Foreign objects are not allowed in `content`. To generate HTML
639
+ * containing foreign objects, create a subclass of
640
+ * `HTML.ToHTMLVisitor` and override `visitObject`.
641
+ */
642
+ HTML . toHTML = function ( content ) {
643
+ return ( new HTML . ToHTMLVisitor ) . visit ( content ) ;
644
+ } ;
645
+
625
646
// Escaping modes for outputting text when generating HTML.
626
647
HTML . TEXTMODE = {
627
648
STRING : 1 ,
@@ -631,6 +652,31 @@ HTML.TEXTMODE = {
631
652
632
653
/**
633
654
* ## HTML.toText(content, textMode)
655
+ *
656
+ * * `content` - any HTMLjs content
657
+ * * `textMode` - the type of text to generate; one of
658
+ * `HTML.TEXTMODE.STRING`, `HTML.TEXTMODE.RCDATA`, or
659
+ * `HTML.TEXTMODE.ATTRIBUTE`
660
+ *
661
+ * Generating HTML or DOM from HTMLjs content requires generating text
662
+ * for attribute values and for the contents of TEXTAREA elements,
663
+ * among others. The input content may contain strings, arrays,
664
+ * booleans, numbers, nulls, and CharRefs. Behavior on other types
665
+ * is undefined.
666
+ *
667
+ * The required `textMode` argument specifies the type of text to
668
+ * generate:
669
+ *
670
+ * * `HTML.TEXTMODE.STRING` - a string with no special
671
+ * escaping or encoding performed, suitable for passing to
672
+ * `setAttribute` or `document.createTextNode`.
673
+ * * `HTML.TEXTMODE.RCDATA` - a string with `<` and `&` encoded
674
+ * as character references (and CharRefs included in their
675
+ * "HTML" form), suitable for including in a string of HTML
676
+ * * `HTML.TEXTMODE.ATTRIBUTE` - a string with `"` and `&` encoded
677
+ * as character references (and CharRefs included in their
678
+ * "HTML" form), suitable for including in an HTML attribute
679
+ * value surrounded by double quotes
634
680
*/
635
681
636
682
HTML . toText = function ( content , textMode ) {
@@ -644,10 +690,3 @@ HTML.toText = function (content, textMode) {
644
690
var visitor = new HTML . ToTextVisitor ( { textMode : textMode } ) ; ;
645
691
return visitor . visit ( content ) ;
646
692
} ;
647
-
648
- /**
649
- * ## HTML.toHTML(content)
650
- */
651
- HTML . toHTML = function ( content ) {
652
- return ( new HTML . ToHTMLVisitor ) . visit ( content ) ;
653
- } ;
0 commit comments