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) func()
- func InsertInvisible(pos *gtk.TextIter, txt string)
- func IsUnicodeEmoji(v string) bool
- func NewSeparator() *gtk.Separator
- func ParseAndWalk(src []byte, w ast.Walker) error
- func WYSIWYG(ctx context.Context, buffer *gtk.TextBuffer)
- func WalkChildren(n ast.Node, walker ast.Walker) ast.WalkStatus
- 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(), )
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 ¶
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 ¶
ParseAndWalk parses src and walks its Markdown AST tree.
func WYSIWYG ¶
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 ¶
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.