md

package
v0.0.0-...-bd1a654 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package md provides Markdown helper functions as well as styling.

Index

Constants

View Source
const EmojiScale = 2.5

EmojiScale is the scale of Unicode emojis.

Variables

Converter is the default converter that outputs HTML.

EmojiAttrs is the Pango attributes set for a label showing an emoji. It is kept the same as the _emoji tag in TextTags.

Parser is the default Markdown parser.

Renderer is the default Markdown renderer.

View Source
var Tags = textutil.TextTagsMap{

	"h1":     HTag(1.35),
	"h2":     HTag(1.18),
	"h3":     HTag(1.00),
	"h4":     HTag(0.91),
	"h5":     HTag(0.83),
	"h6":     HTag(0.75),
	"em":     {"style": pango.StyleItalic},
	"i":      {"style": pango.StyleItalic},
	"strong": {"weight": pango.WeightBold},
	"b":      {"weight": pango.WeightBold},
	"u":      {"underline": pango.UnderlineSingle},
	"strike": {"strikethrough": true},
	"del":    {"strikethrough": true},
	"sup":    {"rise": +6000, "scale": 0.7},
	"sub":    {"rise": -2000, "scale": 0.7},
	"code": {
		"family":         "Monospace",
		"insert-hyphens": false,
	},
	"caption": {
		"weight": pango.WeightLight,
		"style":  pango.StyleItalic,
		"scale":  0.8,
	},

	"blockquote": {
		"foreground":  "#789922",
		"left-margin": 12,
	},

	"htmltag": {
		"family":     "Monospace",
		"foreground": "#808080",
	},

	"_invisible": {"editable": false, "invisible": true},
	"_immutable": {"editable": false},
	"_emoji":     {"scale": EmojiScale},
	"_image":     {"rise": -2 * pango.SCALE},
	"_nohyphens": {"insert-hyphens": false},
}

Tags contains the tag table mapping most Matrix HTML tags to GTK TextTags.

Functions

func AddWidgetAt

func AddWidgetAt(text *gtk.TextView, iter *gtk.TextIter, w gtk.Widgetter)

AddWidgetAt adds a widget into the text view at the current iterator position.

func BeginImmutable

func BeginImmutable(pos *gtk.TextIter) (end func())

BeginImmutable begins the immutability region in the text buffer that the text iterator belongs to. Calling the returned callback will end the immutable region. Calling it is not required, but the given iterator must still be valid when it's called.

func BindLinkHandler

func BindLinkHandler(tview *gtk.TextView, onURL func(string))

BindLinkHandler binds input handlers for triggering hyperlinks within the TextView. If BindLinkHandler is called on the same TextView again, then it does nothing. The function checks this by checking for the .gmd-hyperlinked class.

func HTag

func HTag(scale float64) textutil.TextTag

HTag creates a new TextTag for the heading with the given scale.

func InsertInvisible

func InsertInvisible(pos *gtk.TextIter, txt string)

InsertInvisible inserts an invisible string of text into the buffer. This is useful for inserting invisible textual data during editing.

func IsUnicodeEmoji

func IsUnicodeEmoji(v string) bool

IsUnicodeEmoji returns true if the given string only contains a Unicode emoji.

func ParseAndWalk

func ParseAndWalk(src []byte, w ast.Walker) error

ParseAndWalk parses src and walks its Markdown AST tree.

func URLTagName

func URLTagName(start, end *gtk.TextIter, url string) string

URLTagName creates a new URL tag name from the given URL.

func WalkChildren

func WalkChildren(n ast.Node, walker ast.Walker) ast.WalkStatus

WalkChildren walks n's children nodes using the given walker. WalkSkipChildren is returned unless the walker fails.

Types

type EmbeddedURL

type EmbeddedURL struct {
	From int    `json:"1"`
	To   int    `json:"2"`
	URL  string `json:"u"`
}

EmbeddedURL is a type that describes a URL and its bounds within a text buffer.

func ParseEmbeddedURL

func ParseEmbeddedURL(data string) (EmbeddedURL, bool)

ParseEmbeddedURL parses the inlined data into an embedded URL structure.

type InlineImage

type InlineImage struct {
	gtk.Widgetter
}

InlineImage is an inline image. The actual widget type depends on the constructor.

func InsertCustomImageWidget

func InsertCustomImageWidget(view *gtk.TextView, anchor *gtk.TextChildAnchor, imager gtk.Widgetter) *InlineImage

InsertCustomImageWidget is the custom variant of InsertImageWidget.

func InsertImageWidget

func InsertImageWidget(view *gtk.TextView, anchor *gtk.TextChildAnchor) *InlineImage

InsertImageWidget asynchronously inserts a new image widget. It does so in a way that the text position of the text buffer is not scrambled. Images created using this function will have the ".md-inlineimage" class.

func (*InlineImage) SetSizeRequest

func (i *InlineImage) SetSizeRequest(w, h int)

SetSizeRequest sets the minimum size of the inline image.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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