buildHTML

Write HTML elements to a string or Element.

  1. HTML buildHTML(T range)
  2. TextHTML buildHTML()
    @safe @safe
    buildHTML
    ()

Return Value

Type: TextHTML

A struct that accepts an element block ~ (html) { } and writes the content to a string.

The resulting content will be wrapped in an Element, making it compatible with the old elemi API. Note that metadata is not preserved, so adding attributes or child nodes from Element will not be possible.

Examples

If no arguments are specified, buildHTML() will output to a string. Under the hood, it uses an std.array.Appender.

import std.array;
string stringOutput = buildHTML() ~ (html) {
    html.p ~ "Hello!";
};

Appender!string rangeOutput;
buildHTML(rangeOutput) ~ (html) {
    html.p ~ "Hello!";
};
assert(stringOutput == rangeOutput[]);

See Also

HTML, the stream structure used to output data.

Meta