md

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: AGPL-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.

View Source
var TextTags = textutil.TextTagsMap{

	"h1":     htag(1.75),
	"h2":     htag(1.50),
	"h3":     htag(1.17),
	"h4":     htag(1.00),
	"h5":     htag(0.83),
	"h6":     htag(0.67),
	"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,
	},
	"li": {
		"left-margin": 24,
	},
	"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},
}

TextTags 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) 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 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 NewSeparator

func NewSeparator() *gtk.Separator

NewSeparator creates a new 100px Markdown <hr> widget.

func ParseAndWalk

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

ParseAndWalk parses src and walks its Markdown AST tree.

func WYSIWYG

func WYSIWYG(ctx context.Context, buffer *gtk.TextBuffer)

WYSIWYG styles the given text buffer according to the Markdown content inside it. It is not fully What-You-See-Is-What-You-Get, but it is mostly so.

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 InlineImage

type InlineImage struct {
	*gtk.Image
}

InlineImage is an inline image.

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