Skip to content

Commit 310dcc5

Browse files
committed
Finish documenting htmljs (except visitors)
1 parent bce67e4 commit 310dcc5

File tree

2 files changed

+87
-9
lines changed

2 files changed

+87
-9
lines changed

packages/htmljs/README.md

+41-2
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,46 @@ values.
383383
`attrs` must not contain any foreign objects.
384384

385385

386-
* ## HTML.toText(content, textMode)
386+
## HTML.toHTML(content)
387387

388+
* `content` - any HTMLjs content
388389

389-
* ## HTML.toHTML(content)
390+
Returns a string of HTML generated from `content`.
391+
392+
For example:
393+
394+
```
395+
HTML.toHTML(HTML.HR()) // => "<hr>"
396+
```
397+
398+
Foreign objects are not allowed in `content`. To generate HTML
399+
containing foreign objects, create a subclass of
400+
`HTML.ToHTMLVisitor` and override `visitObject`.
401+
402+
403+
## HTML.toText(content, textMode)
404+
405+
* `content` - any HTMLjs content
406+
* `textMode` - the type of text to generate; one of
407+
`HTML.TEXTMODE.STRING`, `HTML.TEXTMODE.RCDATA`, or
408+
`HTML.TEXTMODE.ATTRIBUTE`
409+
410+
Generating HTML or DOM from HTMLjs content requires generating text
411+
for attribute values and for the contents of TEXTAREA elements,
412+
among others. The input content may contain strings, arrays,
413+
booleans, numbers, nulls, and CharRefs. Behavior on other types
414+
is undefined.
415+
416+
The required `textMode` argument specifies the type of text to
417+
generate:
418+
419+
* `HTML.TEXTMODE.STRING` - a string with no special
420+
escaping or encoding performed, suitable for passing to
421+
`setAttribute` or `document.createTextNode`.
422+
* `HTML.TEXTMODE.RCDATA` - a string with `<` and `&` encoded
423+
as character references (and CharRefs included in their
424+
"HTML" form), suitable for including in a string of HTML
425+
* `HTML.TEXTMODE.ATTRIBUTE` - a string with `"` and `&` encoded
426+
as character references (and CharRefs included in their
427+
"HTML" form), suitable for including in an HTML attribute
428+
value surrounded by double quotes

packages/htmljs/html.js

+46-7
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,27 @@ HTML.flattenAttributes = function (attrs) {
622622

623623
////////////////////////////// TOHTML
624624

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+
625646
// Escaping modes for outputting text when generating HTML.
626647
HTML.TEXTMODE = {
627648
STRING: 1,
@@ -631,6 +652,31 @@ HTML.TEXTMODE = {
631652

632653
/**
633654
* ## 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
634680
*/
635681

636682
HTML.toText = function (content, textMode) {
@@ -644,10 +690,3 @@ HTML.toText = function (content, textMode) {
644690
var visitor = new HTML.ToTextVisitor({textMode: textMode});;
645691
return visitor.visit(content);
646692
};
647-
648-
/**
649-
* ## HTML.toHTML(content)
650-
*/
651-
HTML.toHTML = function (content) {
652-
return (new HTML.ToHTMLVisitor).visit(content);
653-
};

0 commit comments

Comments
 (0)