1.3.1 • Published 1 year ago

telegram-md v1.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

telegram-md

Telegram MarkdownV2 formatter

GitHub CI Codecov NPM

How to install

npm install telegram-md

How to use

import { md } from 'telegram-md'

const message = md`Hello, ${md.bold('World')}!`

api.sendMessage(chatId, md.build(message))

Classes

Markdown

Stores the result of executing md methods. Used to differentiate between normal strings and escaped strings.

Methods

Every method escapes all unescaped input. Input is assumed to be escaped only when it's an instance of Markdown.

md

Template tag which can be used to build markdown formatted messages.

md`Hello, ${md.bold('World')}!` // => Markdown with value 'Hello, *World*\\!'

md.build

Returns message text that cat be safely sent to telegram API.

md.build(md`Hello, ${md.bold('World')}!`) // => 'Hello, *World*\\!'
md.build('Hello, World!') // => 'Hello, World\\!'

md.bold

md.bold('bold *text') // => Markdown with value '*bold \*text*'

md.italic

md.italic('italic *text') // => Markdown with value '_italic \*text_'

md.underline

md.underline('underline') // => Markdown with value '__underline__'

md.strikethrough

md.strikethrough('strikethrough') // => Markdown with value '~strikethrough~'

md.spoiler

md.spoiler('spoiler') // => Markdown with value '||spoiler||'

md.link

md.link('inline URL', 'http://www.example.com/') // => Markdown with value '[inline URL](http://www\\.example\\.com/)'
md.link('inline mention of a user', 'tg://user?id=123456789') // => Markdown with value '[inline mention of a user](tg://user?id\\=123456789)'

md.inlineCode

md.inlineCode('inline fixed-width code') // => Markdown with value '`inline fixed\\-width code`'

md.codeBlock

md.code('pre-formatted fixed-width code block') // => Markdown with value
```
pre\\-formatted fixed\\-width code block
```
md.code('pre-formatted fixed-width code block written in the Python', 'python') // => Markdown with value
```python
pre\\-formatted fixed\\-width code block written in the Python
```
1.3.1

1 year ago

1.3.0

1 year ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.0.0

2 years ago