Skip to content

Version 1.1.4

Choose a tag to compare

@ALiwoto ALiwoto released this 12 Apr 13:24
· 5 commits to master since this release
099e43f
  • simplified and cleaned up the mutable builder API
  • removed a large amount of legacy duplicate methods
  • added explicit Clone() support for copy-style workflows
  • added fenced code block support, including language-tagged code blocks
  • added additive support for nested text styles
  • refactored the internals away from eager string serialization toward a segment-based model
  • improved package documentation and migration guidance

Breaking changes

The builder now follows one 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

Behavior changes for existing methods:

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

These methods still exist, but they now mutate the current markdown instead of implicitly cloning it.

Migration guide

Use the non-This methods directly for mutation.

If older 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()

General rule:

  • old: md.SomeMethod(...) might clone
  • new: md.SomeMethod(...) mutates
  • if you need a copy: md.Clone().SomeMethod(...)

New features

Fenced code blocks

Added plain fenced code block support:

  • GetCodeBlock(text)
  • md.CodeBlock(text)

Added language-tagged fenced code block support:

  • GetCodeBlockLang(lang, text)
  • md.CodeBlockLang(lang, text)

These support secret replacement and the escaping required inside code blocks.

Nested text styles

Added additive nested style support:

  • GetStyled(text, styles...)
  • md.Styled(text, styles...)

Supported style constants:

  • StyleBold
  • StyleItalic
  • StyleUnderline
  • StyleStrike
  • StyleSpoiler

This makes officially supported Telegram style combinations possible, such as bold + italic, and includes MarkdownV2-safe handling for the italic + underline ambiguity case.

Internal improvements

Segment-based internals

The internal builder no longer stores only fully rendered MarkdownV2 strings after every mutation.

Instead, it now stores structured segments and renders them in ToString().

Benefits:

  • less repeated escaping work
  • cleaner support for future nested formatting
  • better foundation for an eventual entity-based model

Dependency cleanup

Removed the previous dependency on github.com/ALiwoto/ssg and replaced the used pieces with standard-library code.

Secret handling improvements

  • global secret storage is now concurrency-safe
  • secret replacement still happens at append/build time, preserving legacy behavior

Documentation improvements

  • expanded WMarkDown interface comments so go doc is more usable
  • updated the README usage examples
  • added a public README section about Telegram’s officially documented nesting rules
  • added a public README migration section for old versions
  • added internal design notes for a future entity-based model

Telegram formatting notes

Telegram officially documents nested message entities in the Bot API.

Relevant references:

Important takeaway:

  • combined formatting is officially supported
  • overlapping entities must be properly nested
  • bold, italic, underline, strike-through, and spoiler can participate in nesting with restrictions
  • code and pre remain special cases