A growing implementation of HTML generation utilities per the HTML Living Standard. More...
Classes | |
| class | sourcemeta::core::HTMLBuffer |
| class | sourcemeta::core::HTMLWriter |
Functions | |
| SOURCEMETA_CORE_HTML_EXPORT auto | sourcemeta::core::html_escape (std::string &text) -> void |
| SOURCEMETA_CORE_HTML_EXPORT auto | sourcemeta::core::html_escape_append (std::string &output, std::string_view input) -> void |
| SOURCEMETA_CORE_HTML_EXPORT auto | sourcemeta::core::html_escape_append (HTMLBuffer &output, std::string_view input) -> void |
A growing implementation of HTML generation utilities per the HTML Living Standard.
This functionality is included as follows:
| class sourcemeta::core::HTMLBuffer |
A fast append-only string buffer
| class sourcemeta::core::HTMLWriter |
A streaming HTML writer that renders directly to a string buffer. No intermediate DOM tree is built. Elements are serialized as methods are called.
Public Member Functions | |
| SOURCEMETA_FORCEINLINE auto | reserve (std::size_t bytes) -> void |
| Pre-allocate the output buffer. | |
| SOURCEMETA_FORCEINLINE auto | close () -> HTMLWriter & |
| SOURCEMETA_FORCEINLINE auto | attribute (std::string_view name, std::string_view value) -> HTMLWriter & |
| SOURCEMETA_FORCEINLINE auto | text (std::string_view content) -> HTMLWriter & |
| SOURCEMETA_FORCEINLINE auto | raw (std::string_view content) -> HTMLWriter & |
| SOURCEMETA_FORCEINLINE auto | str () -> const std::string & |
| Get the rendered HTML string. | |
| auto | write (std::ostream &stream) -> void |
| Write the rendered HTML to an output stream. | |
|
inline |
Add an attribute to the currently open tag. Must be called immediately after an element method and before any content.
|
inline |
Close the most recently opened element. Closing when no element is open has no effect.
|
inline |
Write content without HTML-escaping. This is how the content of a raw-text element is emitted, since escaped text would corrupt it.
|
inline |
Write HTML-escaped text content. The single-argument element shorthand routes through this and therefore also escapes. The HTML serialization emits the content of a raw-text element literally, so escaping its content would corrupt it. This writer does not special-case content by element, so the content of a raw-text element must be written unescaped rather than as escaped text, and it must not contain that element's closing-tag sequence.
| SOURCEMETA_CORE_HTML_EXPORT auto sourcemeta::core::html_escape | ( | std::string & | text | ) | -> void |
HTML character escaping implementation per HTML Living Standard. See: https://html.spec.whatwg.org/multipage/parsing.html#escapingString
This function escapes the five HTML special characters in-place, the ampersand, less-than sign, greater-than sign, double quote, and apostrophe, along with the no-break space, each becoming its corresponding HTML entity.
For example:
| SOURCEMETA_CORE_HTML_EXPORT auto sourcemeta::core::html_escape_append | ( | HTMLBuffer & | output, |
| std::string_view | input ) -> void |
Append the HTML-escaped form of input directly to a buffer. The input must not reference the buffer, since appending to it may relocate its storage.
| SOURCEMETA_CORE_HTML_EXPORT auto sourcemeta::core::html_escape_append | ( | std::string & | output, |
| std::string_view | input ) -> void |
Append the HTML-escaped form of input directly to output, without allocating a temporary string. The input must not reference the output, since appending to the output may relocate its storage.