Skip to content

Commit

Permalink
Merge pull request #201 from augustjune/introducing-markdownv2
Browse files Browse the repository at this point in the history
Added MarkdownV2 parse mode support
  • Loading branch information
augustjune authored Sep 4, 2020
2 parents 1b54d8d + 04015a9 commit 22e0159
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
30 changes: 2 additions & 28 deletions core/shared/src/main/scala/canoe/models/ParseMode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,11 @@ package canoe.models
import io.circe.Encoder

/**
* Formatting options.
* The Bot API supports basic formatting for messages.
* You can use bold and italic text, as well as inline links and pre-formatted code in your bots' messages.
* Telegram clients will render them accordingly. You can use either markdown-style or HTML-style formatting.
* Note that Telegram clients will display an alert to the user before opening an inline link ('Open this link?' together with the full URL).
*
* Markdown style.
* To use this mode, pass Markdown in the parse_mode field when using sendMessage. Use the following syntax in your message:
* *bold text*
* _italic text_
* [text](URL)
* `inline fixed-width code`
* ```pre-formatted fixed-width code block```
*
* HTML style.
* To use this mode, pass HTML in the parse_mode field when using sendMessage. The following tags are currently supported:
* <b>bold</b>, <strong>bold</strong>
* <i>italic</i>, <em>italic</em>
* <a href="URL">inline URL</a>
* <code>inline fixed-width code</code>
* <pre>pre-formatted fixed-width code block</pre>
*
* Please note:
* Only the tags mentioned above are currently supported.
* Tags must not be nested.
* All <, > and & symbols that are not a part of a tag or an HTML entity must be replaced with the corresponding HTML entities (< with &lt;, > with &gt; and & with &amp;).
* All numerical HTML entities are supported.
* The API currently supports only the following named HTML entities: &lt;, &gt;, &amp; and &quot;.
* Telegram supported formatting options.
*/
object ParseMode extends Enumeration {
type ParseMode = Value
val MarkdownV2: ParseMode = Value("MarkdownV2")
val Markdown: ParseMode = Value("Markdown")
val HTML: ParseMode = Value("HTML")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,25 @@ final case class TextContent(text: String,
) extends MessageContent[TextMessage] {

/**
* @return Text content with markdown parse mode.
* Text content with markdown parse mode.
*
* Markdown formatting applied according to MarkdownV2 style.
* Examples and additional information can be found [[https://core.telegram.org/bots/api#markdownv2-style here]].
*/
def markdown: TextContent = copy(parseMode = Some(ParseMode.Markdown))
def markdown: TextContent = copy(parseMode = Some(ParseMode.MarkdownV2))

/**
* @return Text content with HTML parse mode.
* Text content with legacy markdown parse mode.
*
* Markdown formatting applied according to Markdown style.
* Examples and additional information can be found [[https://core.telegram.org/bots/api#markdown-style here]].
*/
def markdownOld: TextContent = copy(parseMode = Some(ParseMode.Markdown))

/**
* Text content with HTML parse mode.
*
* Examples and additional information can be found [[https://core.telegram.org/bots/api#html-style here]].
*/
def html: TextContent = copy(parseMode = Some(ParseMode.HTML))
}
Expand Down

0 comments on commit 22e0159

Please sign in to comment.