mdparser

module
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT

README

mdparser

mdparser for telegram bot API


How to use

First you need to get the package: go get -u github.com/AnimeKaizoku/mdparser

then you can use the package like this:

import "github.com/AnimeKaizoku/mdparser"



func sendMessage(msg Message) {
	md := mdparser.GetBold("This is a message")
	md.Normal(":\n")
	md.Italic("Italic\n")
	md.Styled("Bold + Italic\n", mdparser.StyleBold, mdparser.StyleItalic)
	md.Mono("Mono space\n")
	md.CodeBlockLang("go", "fmt.Println(\"hello\")")
	md.HyperLink("text", "https://google.com")

	msg.Reply(md.ToString(), options{version: "MarkdownV2"})
}


All instance methods mutate the current markdown. If you need a copy first, clone explicitly:

base := mdparser.GetNormal("hello")
copy := base.Clone().Bold(" world")

Nesting Format Entities

Telegram officially documents nested message entities in the Bot API docs:

Important rules from the official docs:

  • Nested entities are supported, but if two entities overlap, one must fully contain the other.
  • bold, italic, underline, strike-through, and spoiler may be nested in each other.
  • code and pre are special and have stricter nesting limits.
  • Legacy Markdown is limited; use MarkdownV2 if you need modern formatting behavior.

That means combined formatting is real and officially supported. For example, bold + italic on the same words is valid when represented according to Telegram's nesting rules.

Migrating From Old Versions

Current rule:

  • Clone() is the only copy operation.
  • All other instance methods mutate the receiver.

Removed methods:

  • AppendThis
  • AppendNormal
  • AppendBold
  • AppendItalic
  • AppendMono
  • AppendUnderline
  • AppendStrike
  • AppendHyperLink
  • AppendMention
  • AppendSpoiler
  • ReplaceMdThis
  • ReplaceMdThisN
  • ElThis
  • SpaceThis
  • TabThis

Replacement pattern:

  • Use the non-This method directly for mutation.
  • If old code expected copy-style behavior, call Clone() first.

Examples:

  • md.AppendBold("x") -> md.Clone().Bold("x")
  • md.AppendBoldThis("x") -> md.Bold("x")
  • md.AppendThis(other) -> md.Append(other)
  • md.ReplaceMdThis(old, new) -> md.ReplaceMd(old, new)
  • md.ElThis() -> md.El()

Behavior changes:

  • Append
  • ReplaceMd
  • ReplaceMdN
  • ReplaceToNew
  • ReplaceToNewN
  • El
  • Space
  • Tab

These methods still exist, but they now mutate the current markdown. If older code relied on copy-style behavior, migrate to md.Clone().SomeMethod(...).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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