$html
Updated on Aug 19, 2025 3 minutes to readThe HTML Plugin provides methods to generate, encode, compile, and sanitize HTML content.
Methods
Method | Description |
---|---|
compile | Compiles a template with parameters and options. |
encode | Encodes a string into HTML entities. |
stripTags | Removes all HTML tags except those explicitly allowed. |
tag | Generates an HTML tag. |
Methods Details
compile()
• Type
(
template: string,
params: object,
options?: CompileOptions
) => string
• Details
Expects a template string, an object with parameters, and optional CompileOptions object.
Returns the compiled HTML as a string.
• Example
const html = E8App.$html.compile(
'<div>Hello, {{name}}!</div>',
{ name: 'Alice' },
{ keepComments: false }
);
// html now contains "<div>Hello, Alice!</div>"
encode()
• Type
(content: string) => string
• Details
Expects a string content to be HTML-encoded.
Returns the encoded string safe for HTML output.
• Example
const encoded = E8App.$html.encode('<div>Hello</div>');
// encoded now contains "<div>Hello</div>"
stripTags()
• Type
(htmlText: string, allowedTags?: string[]) => string
• Details
Expects a string containing HTML and optional array of allowed tag names.
Returns the string with HTML tags removed except for the allowed tags.
• Example
const clean = E8App.$html.stripTags('<b>Hello</b> <i>World</i>', ['b']);
// clean now contains "<b>Hello</b> World"
tag()
• Type
(
name: string,
content?: string,
options?: object
) => string
• Details
Expects a tag name, optional string content, and optional object with additional options (attributes, etc.).
Returns a string containing the generated HTML element.
• Example
const element = E8App.$html.tag('p', 'Hello World', { class: 'text-bold' });
// element now contains '<p class="text-bold">Hello World</p>'