Documentation ¶
Overview ¶
Package md provides Markdown helper functions as well as styling.
Index ¶
- Constants
- Variables
- func AddWidgetAt(text *gtk.TextView, iter *gtk.TextIter, w gtk.Widgetter)
- func BeginImmutable(pos *gtk.TextIter) (end func())
- func BindLinkHandler(tview *gtk.TextView, onURL func(string))
- func HTag(scale float64) textutil.TextTag
- func InsertInvisible(pos *gtk.TextIter, txt string)
- func IsUnicodeEmoji(v string) bool
- func ParseAndWalk(src []byte, w ast.Walker) error
- func URLTagName(start, end *gtk.TextIter, url string) string
- func WalkChildren(n ast.Node, walker ast.Walker) ast.WalkStatus
- type EmbeddedURL
- type InlineImage
Constants ¶
const EmojiScale = 2.5
EmojiScale is the scale of Unicode emojis.
Variables ¶
var Converter = goldmark.New( goldmark.WithParser(Parser), goldmark.WithRenderer( renderer.NewRenderer( renderer.WithNodeRenderers( markutil.Prioritized(Renderer, 1000), ), ), ), )
Converter is the default converter that outputs HTML.
var EmojiAttrs = textutil.Attrs( pango.NewAttrScale(EmojiScale), )
EmojiAttrs is the Pango attributes set for a label showing an emoji. It is kept the same as the _emoji tag in TextTags.
var Parser = parser.NewParser( parser.WithInlineParsers( markutil.Prioritized(parser.NewLinkParser(), 0), markutil.Prioritized(parser.NewAutoLinkParser(), 1), markutil.Prioritized(parser.NewEmphasisParser(), 2), markutil.Prioritized(parser.NewCodeSpanParser(), 3), markutil.Prioritized(parser.NewRawHTMLParser(), 4), ), parser.WithBlockParsers( markutil.Prioritized(parser.NewParagraphParser(), 0), markutil.Prioritized(parser.NewBlockquoteParser(), 1), markutil.Prioritized(parser.NewATXHeadingParser(), 2), markutil.Prioritized(parser.NewFencedCodeBlockParser(), 3), markutil.Prioritized(parser.NewThematicBreakParser(), 4), ), )
Parser is the default Markdown parser.
var Renderer = html.NewRenderer( html.WithHardWraps(), html.WithUnsafe(), )
Renderer is the default Markdown renderer.
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 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 ¶
IsUnicodeEmoji returns true if the given string only contains a Unicode emoji.
func ParseAndWalk ¶
ParseAndWalk parses src and walks its Markdown AST tree.
func URLTagName ¶
URLTagName creates a new URL tag name from the given URL.
func WalkChildren ¶
WalkChildren walks n's children nodes using the given walker. WalkSkipChildren is returned unless the walker fails.
Types ¶
type EmbeddedURL ¶
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.