Overview
The HTML Encoder converts AppFlowy EditorDocument objects into HTML strings. It provides a parser-based system that transforms document nodes into semantic HTML elements.
DocumentHTMLEncoder
The main class for encoding documents to HTML format.Constructor
Parameters
- encodeParsers (
List<HTMLNodeParser>): List of node parsers that define how each node type is converted to HTML. Default is an empty list.
Methods
convert
Document to an HTML string.
Parameters:
input(Document): The document to convert
String - The HTML representation of the document
Example:
Helper Function
documentToHTML
A convenient helper function that provides a simpler API with default parsers.document(Document): The document to convertcustomParsers(List<HTMLNodeParser>): Additional custom parsers to use
String - The HTML string
Example:
Supported Node Types
The encoder converts document nodes to the following HTML elements:Text and Formatting
- Paragraphs:
<p>tags - Bold:
<strong>tags or<span style="font-weight: bold"> - Italic:
<i>or<em>tags or<span style="font-style: italic"> - Underline:
<u>tags or<span style="text-decoration: underline"> - Strikethrough:
<del>or<s>tags or<span style="text-decoration: line-through"> - Code:
<code>tags - Links:
<a href="...">tags
Block Elements
- Headings:
<h1>through<h6>tags - Bulleted Lists:
<ul>with<li>items - Numbered Lists:
<ol>with<li>items - Todo Lists:
<ul>with<li>containing checkbox indicators - Block Quotes:
<blockquote>tags - Images:
<img>tags withsrcandalignattributes - Tables:
<table>with proper structure - Dividers:
<hr>tags - Line Breaks:
<br>tags
Example Output
Inline Styles
The encoder generates inline styles for certain attributes:Nested Content
The encoder properly handles nested structures:Custom Parsers
Create custom HTML parsers by implementing theHTMLNodeParser interface:
Table Support
The encoder generates proper HTML table structure:Empty Paragraphs
Empty paragraphs are converted to<br> tags:
See Also
- HTML Decoder - Parse HTML to documents
- Markdown Encoder - Convert documents to Markdown