GMimeHtmlToHtml

GMimeHtmlToHtml — HTML rewriting with callbacks and compliance reporting

Functions

Types and Values

Description

Rewrites HTML with optional comment filtering, fragment output, noscript handling and tag callbacks. Compliance diagnostics describe lexical and structural recovery without changing the output.

This converter is not a sanitizer. In particular, raw HTML headers and footers bypass filtering and callbacks.

Functions

g_mime_html_to_html_new ()

GMimeTextConverter *
g_mime_html_to_html_new (void);

Creates an HTML rewriting converter. By default, comments and document structure are retained, noscript elements are unwrapped, and headers and footers are interpreted as plain text. This converter is not a sanitizer.

Returns

a new GMimeHtmlToHtml.

[transfer full]


g_mime_html_to_html_get_filter_comments ()

gboolean
g_mime_html_to_html_get_filter_comments
                               (GMimeHtmlToHtml *converter);

Gets whether HTML comments are omitted from the output.

Parameters

converter

a GMimeHtmlToHtml

 

Returns

TRUE if comments are filtered, or FALSE if retained (the default).


g_mime_html_to_html_set_filter_comments ()

void
g_mime_html_to_html_set_filter_comments
                               (GMimeHtmlToHtml *converter,
                                gboolean value);

Enables or disables comment filtering. Removing comments does not make the output safe for use as untrusted HTML.

Parameters

converter

a GMimeHtmlToHtml

 

value

whether to omit HTML comments

 

g_mime_html_to_html_get_output_html_fragment ()

gboolean
g_mime_html_to_html_get_output_html_fragment
                               (GMimeHtmlToHtml *converter);

Gets whether document structure is removed to produce a fragment.

Parameters

converter

a GMimeHtmlToHtml

 

Returns

TRUE for fragment output, or FALSE to retain document structure (the default).


g_mime_html_to_html_set_output_html_fragment ()

void
g_mime_html_to_html_set_output_html_fragment
                               (GMimeHtmlToHtml *converter,
                                gboolean value);

When enabled, omits the doctype, html and body tags, and the head element with its contents. Configured headers and footers are still included. When disabled, document structure from the input is retained rather than synthesizing wrappers around an input fragment.

Parameters

converter

a GMimeHtmlToHtml

 

value

whether to produce an HTML fragment

 

g_mime_html_to_html_get_max_element_depth ()

guint
g_mime_html_to_html_get_max_element_depth
                               (GMimeHtmlToHtml *converter);

Gets the tokenizer's maximum number of distinct open-element stack entries.

Parameters

converter

a GMimeHtmlToHtml

 

Returns

the element depth limit, initially 4096.


g_mime_html_to_html_set_max_element_depth ()

void
g_mime_html_to_html_set_max_element_depth
                               (GMimeHtmlToHtml *converter,
                                guint value);

Limits the tokenizer's distinct open-element stack entries. By default, the tag that exceeds the limit is processed and the remaining input is treated as literal text. See g_mime_html_to_html_set_limit_exceeded_behavior(). A depth-limit diagnostic is reported when a compliance logger is registered.

Parameters

converter

a GMimeHtmlToHtml

 

value

the maximum element depth, from 1 to G_MAXINT

 

g_mime_html_to_html_get_formatting_recovery_enabled ()

gboolean
g_mime_html_to_html_get_formatting_recovery_enabled
                               (GMimeHtmlToHtml *converter);

Parameters

converter

a GMimeHtmlToHtml

 

Returns

TRUE if bounded formatting recovery is enabled (default: FALSE).


g_mime_html_to_html_set_formatting_recovery_enabled ()

void
g_mime_html_to_html_set_formatting_recovery_enabled
                               (GMimeHtmlToHtml *converter,
                                gboolean enabled);

Follow reconstructed formatting when interpreting malformed HTML. This does not synthesize tag callbacks or guarantee browser-equivalent parsing. If recovery cannot continue, the remaining visible input is written as literal text unless g_mime_html_to_html_set_limit_exceeded_behavior() selects failure. With recovery disabled, malformed formatting mixed with SVG or MathML can make a source tag part of text or a comment, so the callback will not see it.

Parameters

converter

a GMimeHtmlToHtml

 

enabled

whether to track formatting elements that may be reopened

 

g_mime_html_to_html_get_limit_exceeded_behavior ()

GMimeHtmlLimitExceededBehavior
g_mime_html_to_html_get_limit_exceeded_behavior
                               (GMimeHtmlToHtml *converter);

Parameters

converter

a GMimeHtmlToHtml

 

Returns

the structural limit policy, initially GMIME_HTML_LIMIT_EXCEEDED_BEHAVIOR_LITERAL_TEXT.


g_mime_html_to_html_set_limit_exceeded_behavior ()

void
g_mime_html_to_html_set_limit_exceeded_behavior
                               (GMimeHtmlToHtml *converter,
                                GMimeHtmlLimitExceededBehavior value);

By default the remaining input is processed as text, not markup. In fail mode conversion stops with GMIME_ERROR_PARSE_ERROR in the GMIME_ERROR domain before the triggering token is processed by the converter. Output already written to the destination is not rolled back.

Parameters

converter

a GMimeHtmlToHtml

 

value

the behavior when structural tracking exceeds its limits

 

g_mime_html_to_html_get_header_format ()

GMimeHeaderFooterFormat
g_mime_html_to_html_get_header_format (GMimeHtmlToHtml *converter);

Gets how the configured header is interpreted.

Parameters

converter

a GMimeHtmlToHtml

 

Returns

the header format, initially GMIME_HEADER_FOOTER_FORMAT_TEXT.


g_mime_html_to_html_set_header_format ()

void
g_mime_html_to_html_set_header_format (GMimeHtmlToHtml *converter,
                                       GMimeHeaderFooterFormat value);

Selects how the header set by g_mime_text_converter_set_header() is written. Text is independently converted to HTML. HTML is copied verbatim without filtering, sanitization or tag callbacks.

Parameters

converter

a GMimeHtmlToHtml

 

value

the format of the configured header

 

g_mime_html_to_html_get_footer_format ()

GMimeHeaderFooterFormat
g_mime_html_to_html_get_footer_format (GMimeHtmlToHtml *converter);

Gets how the configured footer is interpreted.

Parameters

converter

a GMimeHtmlToHtml

 

Returns

the footer format, initially GMIME_HEADER_FOOTER_FORMAT_TEXT.


g_mime_html_to_html_set_footer_format ()

void
g_mime_html_to_html_set_footer_format (GMimeHtmlToHtml *converter,
                                       GMimeHeaderFooterFormat value);

Selects how the footer set by g_mime_text_converter_set_footer() is written. Text is independently converted to HTML. HTML is copied verbatim without filtering, sanitization or tag callbacks.

Parameters

converter

a GMimeHtmlToHtml

 

value

the format of the configured footer

 

g_mime_html_to_html_get_no_script_handling ()

GMimeHtmlNoScriptHandling
g_mime_html_to_html_get_no_script_handling
                               (GMimeHtmlToHtml *converter);

Gets how noscript elements and their contents are parsed and written.

Parameters

converter

a GMimeHtmlToHtml

 

Returns

the noscript mode, initially GMIME_HTML_NO_SCRIPT_HANDLING_UNWRAP.


g_mime_html_to_html_set_no_script_handling ()

void
g_mime_html_to_html_set_no_script_handling
                               (GMimeHtmlToHtml *converter,
                                GMimeHtmlNoScriptHandling value);

Selects noscript parsing and output. The default unwrap mode parses its contents as HTML and removes the noscript tags independently of the renderer's scripting setting. The other modes require the renderer's scripting setting to match the selected mode. None of these modes makes the converter a sanitizer.

Parameters

converter

a GMimeHtmlToHtml

 

value

the noscript handling mode

 

g_mime_html_to_html_set_html_tag_callback ()

void
g_mime_html_to_html_set_html_tag_callback
                               (GMimeHtmlToHtml *converter,
                                GMimeHtmlTagCallback callback,
                                gpointer user_data,
                                GDestroyNotify destroy);

Sets the HTML tag callback, or restores default tag output if callback is NULL. The callback must explicitly write any desired tag; end-tag callbacks are opt-in through GMimeHtmlTagContext. Headers and footers do not invoke the callback.

The previous destroy notifier is called when replacing the registration. destroy is called when this registration is replaced or the converter is finalized. The callback cannot be changed during conversion.

Parameters

converter

a GMimeHtmlToHtml

 

callback

the HTML tag callback.

[nullable][scope notified][closure user_data][destroy destroy]

user_data

data passed to the callback.

[nullable]

destroy

destroy notifier for user_data .

[nullable]

g_mime_html_to_html_get_html_tag_callback ()

GMimeHtmlTagCallback
g_mime_html_to_html_get_html_tag_callback
                               (GMimeHtmlToHtml *converter,
                                gpointer *user_data);

Gets the currently registered HTML tag callback.

[skip]

Parameters

converter

a GMimeHtmlToHtml

 

user_data

the callback's borrowed user data.

[out][optional][nullable][transfer none]

Returns

the HTML tag callback, or NULL if none is registered.

[nullable]


g_mime_html_to_html_set_compliance_logger ()

void
g_mime_html_to_html_set_compliance_logger
                               (GMimeHtmlToHtml *converter,
                                GMimeHtmlComplianceLogger logger,
                                gpointer user_data,
                                GDestroyNotify destroy);

Sets the compliance logger, or clears it if logger is NULL. Diagnostics are borrowed for the duration of the callback and do not change output.

The previous destroy notifier is called when replacing the registration. destroy is called when this registration is replaced or the converter is finalized. The logger cannot be changed during conversion.

Parameters

converter

a GMimeHtmlToHtml

 

logger

the compliance logger.

[nullable][scope notified][closure user_data][destroy destroy]

user_data

data passed to the logger.

[nullable]

destroy

destroy notifier for user_data .

[nullable]

g_mime_html_to_html_get_compliance_logger ()

GMimeHtmlComplianceLogger
g_mime_html_to_html_get_compliance_logger
                               (GMimeHtmlToHtml *converter,
                                gpointer *user_data);

Gets the currently registered HTML compliance logger.

[skip]

Parameters

converter

a GMimeHtmlToHtml

 

user_data

the logger's borrowed user data.

[out][optional][nullable][transfer none]

Returns

the compliance logger, or NULL if none is registered.

[nullable]


g_mime_html_to_html_get_compliance_options ()

GMimeHtmlComplianceOptions *
g_mime_html_to_html_get_compliance_options
                               (GMimeHtmlToHtml *converter);

Gets the converter's HTML compliance options.

Parameters

converter

a GMimeHtmlToHtml

 

Returns

the converter's compliance options.

[transfer none]


g_mime_html_to_html_set_compliance_options ()

void
g_mime_html_to_html_set_compliance_options
                               (GMimeHtmlToHtml *converter,
                                GMimeHtmlComplianceOptions *options);

Sets the compliance options. The converter retains a reference to options .

Parameters

converter

a GMimeHtmlToHtml

 

options

the HTML compliance options.

[transfer none]

Types and Values

GMimeHtmlToHtml

typedef struct _GMimeHtmlToHtml GMimeHtmlToHtml;

Rewrites HTML with optional tag callbacks and compliance reporting. This converter is not an HTML sanitizer.


enum GMimeHtmlNoScriptHandling

Controls noscript parsing and output in GMimeHtmlToHtml. Normal filtering and tag callbacks still apply. These modes do not make the converter a sanitizer.

Members

GMIME_HTML_NO_SCRIPT_HANDLING_UNWRAP

Parse with scripting disabled and omit the noscript start and end tags while processing their contents as HTML. This is the default, renderer-independent mode.

 

GMIME_HTML_NO_SCRIPT_HANDLING_SCRIPTING_ENABLED

Parse with scripting enabled, treating noscript contents as raw text and retaining the noscript tags. The output renderer must also have scripting enabled.

 

GMIME_HTML_NO_SCRIPT_HANDLING_SCRIPTING_DISABLED

Parse with scripting disabled, processing noscript contents as HTML and retaining the noscript tags. The output renderer must also have scripting disabled.