Documentation ¶
Overview ¶
Package format contains utilities for working with Matrix HTML, specifically methods to parse Markdown into HTML and to parse Matrix HTML into text or markdown.
https://spec.matrix.org/v1.2/client-server-api/#mroommessage-msgtypes
Index ¶
- Constants
- Variables
- func DefaultPillConverter(displayname, mxid, eventID string, ctx Context) string
- func Digits(num int) int
- func HTMLToContent(html string) event.MessageEventContent
- func HTMLToMarkdown(html string) string
- func HTMLToMarkdownAndMentions(html string) (parsed string, mentions *event.Mentions)
- func HTMLToText(html string) string
- func LongestSequence(in string, of rune) int
- func RenderMarkdown(text string, allowMarkdown, allowHTML bool) event.MessageEventContent
- func RenderMarkdownCustom(text string, renderer goldmark.Markdown) event.MessageEventContent
- func UnwrapSingleParagraph(html string) string
- type CodeBlockConverter
- type ColorConverter
- type Context
- type HTMLParser
- type LinkConverter
- type PillConverter
- type SpoilerConverter
- type TagStack
- type TaggedString
- type TextConverter
Constants ¶
View Source
const ContextKeyMentions = "_mentions"
Variables ¶
View Source
var BlockTags = []string{"p", "h1", "h2", "h3", "h4", "h5", "h6", "ol", "ul", "pre", "blockquote", "div", "hr", "table"}
View Source
var Extensions = goldmark.WithExtensions(extension.Strikethrough, extension.Table, mdext.Spoiler)
View Source
var HTMLOptions = goldmark.WithRendererOptions(html.WithHardWraps(), html.WithUnsafe())
Functions ¶
func DefaultPillConverter ¶ added in v0.9.14
func HTMLToContent ¶ added in v0.12.0
func HTMLToContent(html string) event.MessageEventContent
func HTMLToMarkdown ¶ added in v0.12.0
HTMLToMarkdown converts Matrix HTML into markdown with the default settings.
Currently, the only difference to HTMLToText is how links are formatted.
func HTMLToMarkdownAndMentions ¶ added in v0.20.0
func HTMLToText ¶
HTMLToText converts Matrix HTML into text with the default settings.
func LongestSequence ¶ added in v0.14.0
func RenderMarkdown ¶
func RenderMarkdown(text string, allowMarkdown, allowHTML bool) event.MessageEventContent
func RenderMarkdownCustom ¶ added in v0.12.0
func RenderMarkdownCustom(text string, renderer goldmark.Markdown) event.MessageEventContent
func UnwrapSingleParagraph ¶ added in v0.12.0
UnwrapSingleParagraph removes paragraph tags surrounding a string if the string only contains a single paragraph.
Types ¶
type CodeBlockConverter ¶
type ColorConverter ¶ added in v0.12.0
type Context ¶ added in v0.7.0
type Context struct { Ctx context.Context ReturnData map[string]any TagStack TagStack PreserveWhitespace bool }
func NewContext ¶ added in v0.14.0
func (Context) WithWhitespace ¶ added in v0.14.0
type HTMLParser ¶
type HTMLParser struct { PillConverter PillConverter TabsToSpaces int Newline string HorizontalLine string BoldConverter TextConverter ItalicConverter TextConverter StrikethroughConverter TextConverter UnderlineConverter TextConverter LinkConverter LinkConverter SpoilerConverter SpoilerConverter ColorConverter ColorConverter MonospaceBlockConverter CodeBlockConverter MonospaceConverter TextConverter TextConverter TextConverter }
HTMLParser is a somewhat customizable Matrix HTML parser.
type LinkConverter ¶ added in v0.12.0
type PillConverter ¶ added in v0.9.14
type SpoilerConverter ¶ added in v0.12.0
type TaggedString ¶
type TaggedString struct {
// contains filtered or unexported fields
}
TaggedString is a string that also contains a HTML tag.
type TextConverter ¶
Click to show internal directories.
Click to hide internal directories.