mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
renamed Render
to Renderer
This commit is contained in:
parent
0e7582225f
commit
c1873e0b18
2 changed files with 13 additions and 12 deletions
|
@ -13,13 +13,14 @@ mod tag;
|
||||||
|
|
||||||
/// Parses text and message entities to produce the final formatted output.
|
/// Parses text and message entities to produce the final formatted output.
|
||||||
#[derive(Clone, Eq, PartialEq)]
|
#[derive(Clone, Eq, PartialEq)]
|
||||||
pub struct Render<'a> {
|
pub struct Renderer<'a> {
|
||||||
text: &'a str,
|
text: &'a str,
|
||||||
tags: Vec<Tag<'a>>,
|
tags: Vec<Tag<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Render<'a> {
|
impl<'a> Renderer<'a> {
|
||||||
/// Creates a new [`Render`] instance with given text and message entities.
|
/// Creates a new [`Renderer`] instance with given text and message
|
||||||
|
/// entities.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
|
@ -160,7 +161,7 @@ mod test {
|
||||||
MessageEntity { kind: MEK::Underline, offset: 12, length: 10 },
|
MessageEntity { kind: MEK::Underline, offset: 12, length: 10 },
|
||||||
];
|
];
|
||||||
|
|
||||||
let render = Render::new(text, &entities);
|
let render = Renderer::new(text, &entities);
|
||||||
|
|
||||||
assert_eq!(render.as_html(), "<b>Bold</b> <i>italic</i> <u><underline</u>_");
|
assert_eq!(render.as_html(), "<b>Bold</b> <i>italic</i> <u><underline</u>_");
|
||||||
assert_eq!(render.as_markdown(), "**Bold** _\ritalic_\r __\r<underline__\r\\_");
|
assert_eq!(render.as_markdown(), "**Bold** _\ritalic_\r __\r<underline__\r\\_");
|
||||||
|
@ -179,7 +180,7 @@ mod test {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
let render = Render::new(text, &entities);
|
let render = Renderer::new(text, &entities);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
render.as_html(),
|
render.as_html(),
|
||||||
|
@ -200,7 +201,7 @@ mod test {
|
||||||
MessageEntity { kind: MEK::Italic, offset: 10, length: 12 },
|
MessageEntity { kind: MEK::Italic, offset: 10, length: 12 },
|
||||||
];
|
];
|
||||||
|
|
||||||
let render = Render::new(text, &entities);
|
let render = Renderer::new(text, &entities);
|
||||||
|
|
||||||
assert_eq!(render.as_html(), "Some <b>bold <i>both</b> italics</i>");
|
assert_eq!(render.as_html(), "Some <b>bold <i>both</b> italics</i>");
|
||||||
assert_eq!(render.as_markdown(), "Some **bold _\rboth** italics_\r");
|
assert_eq!(render.as_markdown(), "Some **bold _\rboth** italics_\r");
|
||||||
|
@ -232,7 +233,7 @@ mod test {
|
||||||
MessageEntity { kind: MEK::Blockquote, offset: 41, length: 19 },
|
MessageEntity { kind: MEK::Blockquote, offset: 41, length: 19 },
|
||||||
];
|
];
|
||||||
|
|
||||||
let render = Render::new(text, &entities);
|
let render = Renderer::new(text, &entities);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
render.as_html(),
|
render.as_html(),
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use teloxide_core::types::Message;
|
use teloxide_core::types::Message;
|
||||||
|
|
||||||
use super::Render;
|
use super::Renderer;
|
||||||
|
|
||||||
/// Generates HTML and Markdown representations of text and captions in a
|
/// Generates HTML and Markdown representations of text and captions in a
|
||||||
/// Telegram message.
|
/// Telegram message.
|
||||||
|
@ -41,24 +41,24 @@ impl RenderMessageTextHelper for Message {
|
||||||
fn html_text(&self) -> Option<String> {
|
fn html_text(&self) -> Option<String> {
|
||||||
self.text()
|
self.text()
|
||||||
.zip(self.entities())
|
.zip(self.entities())
|
||||||
.map(|(text, entities)| Render::new(text, entities).as_html())
|
.map(|(text, entities)| Renderer::new(text, entities).as_html())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn markdown_text(&self) -> Option<String> {
|
fn markdown_text(&self) -> Option<String> {
|
||||||
self.text()
|
self.text()
|
||||||
.zip(self.entities())
|
.zip(self.entities())
|
||||||
.map(|(text, entities)| Render::new(text, entities).as_markdown())
|
.map(|(text, entities)| Renderer::new(text, entities).as_markdown())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn html_caption(&self) -> Option<String> {
|
fn html_caption(&self) -> Option<String> {
|
||||||
self.caption()
|
self.caption()
|
||||||
.zip(self.caption_entities())
|
.zip(self.caption_entities())
|
||||||
.map(|(text, entities)| Render::new(text, entities).as_html())
|
.map(|(text, entities)| Renderer::new(text, entities).as_html())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn markdown_caption(&self) -> Option<String> {
|
fn markdown_caption(&self) -> Option<String> {
|
||||||
self.caption()
|
self.caption()
|
||||||
.zip(self.caption_entities())
|
.zip(self.caption_entities())
|
||||||
.map(|(text, entities)| Render::new(text, entities).as_markdown())
|
.map(|(text, entities)| Renderer::new(text, entities).as_markdown())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue