htmlutil

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 21 Imported by: 0 modules, 0 packages

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractImageURLs

func ExtractImageURLs(s string) []string

ExtractImageURLs finds image URLs from <img src> tags and <figure data-trix-attachment> elements.

func FromMarkdown added in v1.0.0

func FromMarkdown(md string) string

FromMarkdown converts Markdown the user wrote into HTML for one of HEY's rich-text fields: a message body, a journal entry, a contact note, a snippet.

func MarkdownIsLossless added in v1.8.0

func MarkdownIsLossless(s string) bool

MarkdownIsLossless reports whether ToMarkdown keeps everything in s that FromMarkdown can write back. It is false when s holds something Markdown has no syntax for — a Trix attachment, an image, a table, underline, an attribute such as a colour or a list's starting number, formatting inside code, nesting deeper than ToMarkdown renders, line breaks Markdown cannot place — or a link ToMarkdown will not write, because writing the Markdown back in place of s would lose it.

func MessageSourceText added in v0.2.0

func MessageSourceText(s string) string

MessageSourceText returns the source-backed text carried by HTML message content.

func PrependHTML added in v1.0.0

func PrependHTML(content, note string) string

PrependHTML adds an HTML note before existing HTML content.

func ToText

func ToText(s string) string

ToText converts HTML content to plain text, preserving basic structure.

func UnwrapTrixContent added in v1.8.0

func UnwrapTrixContent(s string) string

UnwrapTrixContent takes off the <div class="trix-content"> that HEY puts around rich text it serves for editing — a contact note's note_html, a journal entry's content_html. That div is Action Text's layout rather than part of what was written, and HEY adds it again on every read, so HTML read from HEY and written back as it is sinks one div deeper each time.

Only the layout is taken off: a div carrying exactly class="trix-content", which is all the layout writes, standing first in the HTML — with or without what was added after it — and again at the start of what it held, which is where earlier round trips nested it. A div like that anywhere else, or one with any other attribute or class, is the author's and is kept. HTML with nothing to take off is returned as it came.

Types

type Attachment

type Attachment struct {
	URL         string
	Filename    string
	ContentType string
	ByteSize    *int64
	SGID        string
	// Embedded reports whether the file comes from an opaque embedded HTML body.
	Embedded bool
}

Attachment describes a downloadable file embedded in rich-text content.

func ExtractAttachments

func ExtractAttachments(s string) []Attachment

ExtractAttachments returns downloadable files in their document order.

type Markdown added in v0.2.0

type Markdown struct {
	// contains filtered or unexported fields
}

Markdown is Markdown that ToMarkdown produced: every context serialized on its own terms, and no control character left in it other than the newlines and tabs that Markdown itself is written with — a fence keeps its tabs, and a sink that shows it sanitizes with the same two allowed. It is the only kind of Markdown markdown.Render accepts, and nothing but ToMarkdown can make one — the field is unexported and there is no constructor — so a body from anywhere else cannot reach a terminal renderer by being a string that happens to look like Markdown. It marshals to JSON as the string it holds, which is what --json carries.

func ToMarkdown added in v0.2.0

func ToMarkdown(s string) Markdown

ToMarkdown converts HTML content to Markdown. Unlike ToText it keeps what a flattened email throws away: link URLs, emphasis, headings, list nesting, quotes, code blocks and tables. What it returns is the only Markdown markdown.Render accepts; see the Markdown type.

func (Markdown) IsEmpty added in v0.2.0

func (m Markdown) IsEmpty() bool

IsEmpty reports Markdown with nothing in it; IsZero is the same, for `omitzero`.

func (Markdown) IsZero added in v0.2.0

func (m Markdown) IsZero() bool

func (Markdown) MarshalText added in v0.2.0

func (m Markdown) MarshalText() ([]byte, error)

MarshalText writes the Markdown as a JSON string.

func (Markdown) String added in v0.2.0

func (m Markdown) String() string

String is the Markdown text, for a sink that writes Markdown rather than rendering it.

Jump to

Keyboard shortcuts

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