htmltext

package
v0.5.39 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: BSD-3-Clause Imports: 17 Imported by: 3 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package htmltext converts HTML and preformatted text with HTML markup to rich text, and rich text to HTML.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FontStyleCSS

func FontStyleCSS(fs *rich.Style, tag string, cssProps map[string]any) bool

FontStyleCSS looks for "tag" name properties in cssProps properties, and applies those to style if found, and returns true -- false if no such tag found

func HTMLPreToRich

func HTMLPreToRich(str []byte, sty *rich.Style, cssProps map[string]any) (rich.Text, error)

HTMLPreToRich translates preformatted HTML-styled text into a rich.Text using given initial text styling parameters and css properties. This uses a custom decoder that preserves all whitespace characters, and decodes all standard inline HTML text style formatting tags in the string. Only basic styling tags, including <span> elements with style parameters (including class names) are decoded. Whitespace is decoded as-is, including LF \n etc, except in WhiteSpacePreLine case which only preserves LF's.

func HTMLToRich

func HTMLToRich(str []byte, sty *rich.Style, cssProps map[string]any) (rich.Text, error)

HTMLToRich translates HTML-formatted rich text into a rich.Text, using given initial text styling parameters and css properties. This uses the golang XML decoder system, which strips all whitespace and therefore does not capture any preformatted text. See HTMLPre. cssProps are a list of css key-value pairs that are used to set styling properties for the text, and can include class names with a value of another property map that is applied to elements of that class, including standard elements like a for links, etc.

func RichToHTML

func RichToHTML(tx rich.Text) string

RichToHTML returns an HTML encoded representation of the rich.Text, with <b>, <i>, and <u> tags for bold, italic, and underlined text, <a> tags for links, and the text escaped.

func SubProperties

func SubProperties(tag string, cssProps map[string]any) (map[string]any, bool)

SubProperties returns a properties map[string]any from given key tag of given properties map, if the key exists and the value is a sub props map. Otherwise returns nil, false

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL