telegold

package module
v0.0.0-...-36dc899 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2022 License: MIT Imports: 6 Imported by: 0

README

Telegold - a Goldmark renderer for Telegram

If you want to publish regular Markdown into Telegram.

The problem

Telegram allows posting both in Markdown and in HTML. But here's the catch: neither is fully functional.

If you choose to post in Markdown, you must escape all special characters not used for formatting. This is only feasible if you hand-craft the messages specifically for Telegram - or if you fully parse and re-render them, defeating the purpose of using Markdown instead of HTML.

If you choose to post in HTML, then only a strictly limited subset of tags is allowed. Worst of all, there is no line break formatting, so you can't reuse the same HTML for web publishing without adding line breaks.

The solution

I wanted to be able to cross-post my blog posts into Telegram, using the same source. As I already use Markdown for posts, and Go for my telegram bot, I decided to extend the Goldmark Markdown parser with a renderer that produces Telegram-compatible HTML.

Usage

md := goldmark.New(goldmark.WithRenderer(telegold.NewRenderer()))
md.Convert(source, &buf) // just use it as usual

As this is simply a renderer, you can combine it with other goldmark options.


(c) 2022 Leonid Shevtsov

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDangerousURL

func IsDangerousURL(url []byte) bool

IsDangerousURL returns true if the given url seems a potentially dangerous url, otherwise false.

func NewRenderer

func NewRenderer() renderer.Renderer

Types

type Renderer

type Renderer struct{}

func (*Renderer) RegisterFuncs

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

RegisterFuncs implements NodeRenderer.RegisterFuncs .

Jump to

Keyboard shortcuts

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