GMimeHtmlWriter

GMimeHtmlWriter — Stateful UTF-8 HTML serialization

Functions

Types and Values

Description

Writes escaped text and attributes using MimeKit's HTML output rules. Start tags remain pending until another tag, text, finish, or flush call. The stream is retained but never closed. Failures can leave partial output; a failed writer should be discarded. Raw markup is not sanitized.

Functions

g_mime_html_writer_new ()

GMimeHtmlWriter *
g_mime_html_writer_new (GMimeStream *stream);

Creates a writer which retains stream without closing it. The caller must finish or flush pending markup before releasing the writer.

Parameters

stream

a stream for UTF-8 output.

[transfer none]

Returns

a new HTML writer.

[transfer full]


g_mime_html_writer_get_state ()

GMimeHtmlWriterState
g_mime_html_writer_get_state (GMimeHtmlWriter *writer);

Gets the current serialization state.

Parameters

writer

a GMimeHtmlWriter

 

Returns

the writer state


g_mime_html_writer_write_start_tag ()

gboolean
g_mime_html_writer_write_start_tag (GMimeHtmlWriter *writer,
                                    const char *name,
                                    GError **error);

Completes any pending tag and begins a start tag. Attributes can be written until the next tag, text, finish or flush operation.

Parameters

writer

a GMimeHtmlWriter

 

name

the UTF-8 tag name

 

error

return location for an error.

[out][optional]

Returns

TRUE on success or FALSE on invalid input or a write error


g_mime_html_writer_write_end_tag ()

gboolean
g_mime_html_writer_write_end_tag (GMimeHtmlWriter *writer,
                                  const char *name,
                                  GError **error);

Completes any pending tag and writes an end tag. The writer does not check whether a matching start tag was written.

Parameters

writer

a GMimeHtmlWriter

 

name

the UTF-8 tag name

 

error

return location for an error.

[out][optional]

Returns

TRUE on success or FALSE on invalid input or a write error


g_mime_html_writer_write_empty_element_tag ()

gboolean
g_mime_html_writer_write_empty_element_tag
                               (GMimeHtmlWriter *writer,
                                const char *name,
                                GError **error);

Completes any pending tag and begins an empty-element tag. Attributes can be written before the tag is completed with a trailing slash.

Parameters

writer

a GMimeHtmlWriter

 

name

the UTF-8 tag name

 

error

return location for an error.

[out][optional]

Returns

TRUE on success or FALSE on invalid input or a write error


g_mime_html_writer_write_attribute ()

gboolean
g_mime_html_writer_write_attribute (GMimeHtmlWriter *writer,
                                    const char *name,
                                    const char *value,
                                    GError **error);

Writes an attribute in a pending start or empty-element tag, escaping and quoting its value when provided.

Parameters

writer

a GMimeHtmlWriter

 

name

the UTF-8 attribute name

 

value

the NUL-terminated UTF-8 value, or NULL for a valueless attribute.

[nullable]

error

return location for an error.

[out][optional]

Returns

TRUE on success or FALSE on invalid input, an invalid writer state or a write error


g_mime_html_writer_write_html_attribute ()

gboolean
g_mime_html_writer_write_html_attribute
                               (GMimeHtmlWriter *writer,
                                const GMimeHtmlAttribute *attribute,
                                GError **error);

Writes attribute in a pending start or empty-element tag. Unlike g_mime_html_writer_write_attribute(), this accepts tokenizer-produced names without revalidating them. The value is escaped and quoted when present.

Parameters

writer

a GMimeHtmlWriter

 

attribute

an HTML attribute.

[transfer none]

error

return location for an error.

[out][optional]

Returns

TRUE on success or FALSE on an invalid value, an invalid writer state or a write error


g_mime_html_writer_write_attribute_name ()

gboolean
g_mime_html_writer_write_attribute_name
                               (GMimeHtmlWriter *writer,
                                const char *name,
                                GError **error);

Writes an attribute name in a pending start or empty-element tag. An attribute value is optional; writing another name leaves this one valueless.

Parameters

writer

a GMimeHtmlWriter

 

name

the UTF-8 attribute name

 

error

return location for an error.

[out][optional]

Returns

TRUE on success or FALSE on invalid input, an invalid writer state or a write error


g_mime_html_writer_write_attribute_value ()

gboolean
g_mime_html_writer_write_attribute_value
                               (GMimeHtmlWriter *writer,
                                const char *value,
                                GError **error);

Escapes and quotes value for the most recently written attribute name. The writer must be in the GMIME_HTML_WRITER_STATE_ATTRIBUTE state.

Parameters

writer

a GMimeHtmlWriter

 

value

the NUL-terminated UTF-8 attribute value

 

error

return location for an error.

[out][optional]

Returns

TRUE on success or FALSE on invalid input, an invalid writer state or a write error


g_mime_html_writer_write_text ()

gboolean
g_mime_html_writer_write_text (GMimeHtmlWriter *writer,
                               const char *text,
                               gssize length,
                               GError **error);

Completes any pending tag and writes escaped text using g_mime_html_encode().

Parameters

writer

a GMimeHtmlWriter

 

text

NUL-free UTF-8 text

 

length

the byte length of text , or -1 for a NUL-terminated string

 

error

return location for an error.

[out][optional]

Returns

TRUE on success or FALSE on invalid input or a write error


g_mime_html_writer_write_markup_text ()

gboolean
g_mime_html_writer_write_markup_text (GMimeHtmlWriter *writer,
                                      const char *text,
                                      gssize length,
                                      GError **error);

Completes any pending tag and writes text verbatim. The markup is not escaped, parsed or sanitized.

Parameters

writer

a GMimeHtmlWriter

 

text

NUL-free UTF-8 markup

 

length

the byte length of text , or -1 for a NUL-terminated string

 

error

return location for an error.

[out][optional]

Returns

TRUE on success or FALSE on invalid input or a write error


g_mime_html_writer_write_token ()

gboolean
g_mime_html_writer_write_token (GMimeHtmlWriter *writer,
                                GMimeHtmlToken *token,
                                GError **error);

Completes any pending tag and serializes token , preserving embedded NUL bytes in token data. The token is not sanitized and remains owned by the caller. A serialized tag is complete and cannot receive further attributes.

Parameters

writer

a GMimeHtmlWriter

 

token

the token to serialize.

[transfer none]

error

return location for an error.

[out][optional]

Returns

TRUE on success or FALSE on a write error


g_mime_html_writer_finish ()

gboolean
g_mime_html_writer_finish (GMimeHtmlWriter *writer,
                           GError **error);

Completes any pending start or empty-element tag without flushing or closing the underlying stream. Does not write matching end tags.

Parameters

writer

a GMimeHtmlWriter

 

error

return location for an error.

[out][optional]

Returns

TRUE on success or FALSE on error


g_mime_html_writer_flush ()

gboolean
g_mime_html_writer_flush (GMimeHtmlWriter *writer,
                          GError **error);

Completes any pending tag and flushes the underlying stream without closing it. Does not write matching end tags.

Parameters

writer

a GMimeHtmlWriter

 

error

return location for an error.

[out][optional]

Returns

TRUE on success or FALSE on a write or flush error

Types and Values

GMimeHtmlWriter

typedef struct _GMimeHtmlWriter GMimeHtmlWriter;

A stateful writer for UTF-8 HTML markup, text and attributes.


enum GMimeHtmlWriterState

The current serialization state of a GMimeHtmlWriter. Writing an attribute value returns the writer to the tag state. Finishing a pending tag returns the writer to the default state.

Members

GMIME_HTML_WRITER_STATE_DEFAULT

No tag is pending; attributes cannot be written.

 

GMIME_HTML_WRITER_STATE_TAG

A start or empty-element tag is pending and an attribute name can be written.

 

GMIME_HTML_WRITER_STATE_ATTRIBUTE

An attribute name has been written in a pending tag; its optional value can be written.