tgmd

package module
v0.0.0-...-1143ea6 Latest Latest
Warning

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

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

README

goldmark-tgmd ✨

goldmark-tgmd is an extension for the goldmark Markdown parser that adds support for Telegram-specific Markdown features 🚀. This library allows developers to render Markdown text according to Telegram's formatting options, making it easier to create content for bots 🤖 and applications integrated with Telegram 📱.

Features 🌟

  • Support for Telegram Markdown features including custom entities like hidden text and strikethrough text. 📝
  • Easy integration with goldmark-based projects. 🔌
  • Extensible architecture for further customizations. 🔨

Getting Started 🚀

Prerequisites 📋
  • Go 1.19 or higher
Installation 💽

To install goldmark-tgmd, use the following go get command:

go get github.com/Mad-Pixels/goldmark-tgmd
Usage 🛠️
package main

import (
   "bytes"
   "fmt"
   "os"
   
   tgmd "github.com/Mad-Pixels/goldmark-tgmd"
)

func main() {
   var buf bytes.Buffer
   content, _ := os.ReadFile("./examples/source.md")
   
   md := tgmd.TGMD()
   _ = md.Convert(content, &buf)
   fmt.Println(buf.String())
}

You can try example

Contributing 🤝

Contributions are welcome! Feel free to open issues for bugs 🐛, feature requests 🌈, or submit pull requests 💡.

Acknowledgments 💖

  • Thanks to the goldmark project for providing a robust and extensible Markdown parser.
  • This project is inspired by the formatting options available in Telegram.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Config = &config{
	headings: [6]Element{
		{
			Style:  BoldTg,
			Prefix: "",
		},
		{
			Style:  BoldTg,
			Prefix: "",
		},
		{
			Style:  BoldTg,
			Prefix: "",
		},
		{
			Style:  ItalicsTg,
			Prefix: "",
		},
		{
			Style:  ItalicsTg,
			Prefix: "",
		},
		{
			Style:  ItalicsTg,
			Prefix: "",
		},
	},
	listBullets: [3]rune{
		CircleSymbol.Rune(),
		SquareSymbol.Rune(),
		TriangleSymbol.Rune(),
	},
}
View Source
var DoubleSpace = &doubleSpace{}

DoubleSpace ...

View Source
var Hidden = &hidden{}
View Source
var KindDoubleSpace = gast.NewNodeKind("DoubleSpace")
View Source
var KindHidden = ast.NewNodeKind("Hidden")
View Source
var Strikethroughs = &strikethrough{}

Functions

func NewDoubleSpaceParser

func NewDoubleSpaceParser() parser.InlineParser

NewDoubleSpaceParser ...

func NewHiddenParser

func NewHiddenParser() parser.InlineParser

NewHiddenParser initialize parser.InlineParser.

func NewRenderer

func NewRenderer() renderer.NodeRenderer

NewRenderer initialize Renderer as renderer.NodeRenderer.

func StringToBytes

func StringToBytes(v string) (b []byte)

StringToBytes convert a string to a byte slice.

func TGMD

func TGMD() goldmark.Markdown

TGMD (telegramMarkdown) endpoint.

Types

type Element

type Element struct {
	Style   SpecialTag
	Prefix  string
	Postfix string
}

Element styles object.

type HiddenAST

type HiddenAST struct {
	ast.BaseInline
}

HiddenAST abstract semantic tree for "hidden".

func NewHidden

func NewHidden() *HiddenAST

NewHidden initialize HiddenAST object.

func (*HiddenAST) Dump

func (n *HiddenAST) Dump(source []byte, level int)

Dump implements Node.Dump.

func (*HiddenAST) Kind

func (n *HiddenAST) Kind() ast.NodeKind

Kind implements Node.Kind.

type Renderer

type Renderer struct{}

Renderer implement renderer.NodeRenderer object.

func (*Renderer) RegisterFuncs

func (r *Renderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)

RegisterFuncs add AST objects to Renderer.

type SpecialChar

type SpecialChar byte

SpecialChar define custom byte object.

const (
	UnderscoreChar   SpecialChar = '_'
	AsteriskChar     SpecialChar = '*'
	OpenBracketChar  SpecialChar = '['
	CloseBracketChar SpecialChar = ']'
	OpenParenChar    SpecialChar = '('
	CloseParenChar   SpecialChar = ')'
	OpenBraceChar    SpecialChar = '{'
	CloseBraceChar   SpecialChar = '}'
	HashChar         SpecialChar = '#'
	PlusChar         SpecialChar = '+'
	MinusChar        SpecialChar = '-'
	EqualChar        SpecialChar = '='
	DotChar          SpecialChar = '.'
	TildeChar        SpecialChar = '~'
	PipeChar         SpecialChar = '|'
	ExclamationChar  SpecialChar = '!'
	GreaterThanChar  SpecialChar = '>'
	LessThanChar     SpecialChar = '<'
	BackqouteChar    SpecialChar = '`'
	SpaceChar        SpecialChar = ' '
	NewLineChar      SpecialChar = '\n'
	SlashChar        SpecialChar = '\\'
	TabChar          SpecialChar = '\t'
)

define characters.

func (SpecialChar) Byte

func (sc SpecialChar) Byte() byte

Byte from SpecialChar.

func (SpecialChar) Bytes

func (sc SpecialChar) Bytes(num int) []byte

func (SpecialChar) Escaped

func (sc SpecialChar) Escaped() []byte

Escaped return SpecialChar as escaped byte char.

type SpecialRune

type SpecialRune rune

SpecialRune define custom rune object.

const (
	CircleSymbol   SpecialRune = '•'
	TriangleSymbol SpecialRune = '⁃'
	SquareSymbol   SpecialRune = '‣'
)

define symbols.

func (SpecialRune) Rune

func (sr SpecialRune) Rune() rune

Rune from SpecialRune.

type SpecialTag

type SpecialTag []SpecialChar

SpecialTag define Markdown formatting characters.

func (SpecialTag) Bytes

func (st SpecialTag) Bytes() []byte

Bytes from SpecialTags.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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