format

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: MPL-2.0 Imports: 9 Imported by: 41

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://matrix.org/docs/spec/client_server/r0.6.0#m-room-message-msgtypes

Index

Constants

This section is empty.

Variables

View Source
var AntiParagraphRegex = regexp.MustCompile("^<p>(.+?)</p>$")
View Source
var BlockTags = []string{"p", "h1", "h2", "h3", "h4", "h5", "h6", "ol", "ul", "pre", "blockquote", "div", "hr", "table"}
View Source
var Extensions = blackfriday.WithExtensions(blackfriday.NoIntraEmphasis |
	blackfriday.Tables |
	blackfriday.FencedCode |
	blackfriday.Strikethrough |
	blackfriday.SpaceHeadings |
	blackfriday.DefinitionLists |
	blackfriday.HardLineBreak)
View Source
var MatrixToURL = regexp.MustCompile("^(?:https?://)?(?:www\\.)?matrix\\.to/#/([#@!+].*)(?:/(\\$.+))?")

MatrixToURL is the regex for parsing matrix.to URLs. https://matrix.org/docs/spec/appendices#matrix-to-navigation

View Source
var NoHTMLRenderer = blackfriday.WithRenderer(&EscapingRenderer{bfhtml})
View Source
var Renderer = blackfriday.WithRenderer(bfhtml)

Functions

func Digits

func Digits(num int) int

Digits counts the number of digits in a non-negative integer.

func HTMLToText

func HTMLToText(html string) string

HTMLToText converts Matrix HTML into text with the default settings.

func RenderMarkdown

func RenderMarkdown(text string, allowMarkdown, allowHTML bool) event.MessageEventContent

Types

type CodeBlockConverter

type CodeBlockConverter func(code, language string, ctx Context) string

type Context added in v0.7.0

type Context map[string]interface{}

type EscapingRenderer

type EscapingRenderer struct {
	*blackfriday.HTMLRenderer
}

func (*EscapingRenderer) RenderNode

func (r *EscapingRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering bool) blackfriday.WalkStatus

type HTMLParser

type HTMLParser struct {
	PillConverter           func(mxid, eventID string, ctx Context) string
	TabsToSpaces            int
	Newline                 string
	HorizontalLine          string
	BoldConverter           TextConverter
	ItalicConverter         TextConverter
	StrikethroughConverter  TextConverter
	UnderlineConverter      TextConverter
	MonospaceBlockConverter CodeBlockConverter
	MonospaceConverter      TextConverter
}

HTMLParser is a somewhat customizable Matrix HTML parser.

func (*HTMLParser) Parse

func (parser *HTMLParser) Parse(htmlData string, ctx Context) string

Parse converts Matrix HTML into text using the settings in this parser.

type TaggedString

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

TaggedString is a string that also contains a HTML tag.

type TextConverter

type TextConverter func(string, Context) string

Jump to

Keyboard shortcuts

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