renamed Render to Renderer

This commit is contained in:
YouKnow 2024-10-22 03:04:18 +03:30
parent 0e7582225f
commit c1873e0b18
2 changed files with 13 additions and 12 deletions

View file

@ -13,13 +13,14 @@ mod tag;
/// Parses text and message entities to produce the final formatted output.
#[derive(Clone, Eq, PartialEq)]
pub struct Render<'a> {
pub struct Renderer<'a> {
text: &'a str,
tags: Vec<Tag<'a>>,
}
impl<'a> Render<'a> {
/// Creates a new [`Render`] instance with given text and message entities.
impl<'a> Renderer<'a> {
/// Creates a new [`Renderer`] instance with given text and message
/// entities.
///
/// # Arguments
///
@ -160,7 +161,7 @@ mod test {
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>&lt;underline</u>_");
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!(
render.as_html(),
@ -200,7 +201,7 @@ mod test {
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_markdown(), "Some **bold _\rboth** italics_\r");
@ -232,7 +233,7 @@ mod test {
MessageEntity { kind: MEK::Blockquote, offset: 41, length: 19 },
];
let render = Render::new(text, &entities);
let render = Renderer::new(text, &entities);
assert_eq!(
render.as_html(),

View file

@ -3,7 +3,7 @@
use teloxide_core::types::Message;
use super::Render;
use super::Renderer;
/// Generates HTML and Markdown representations of text and captions in a
/// Telegram message.
@ -41,24 +41,24 @@ impl RenderMessageTextHelper for Message {
fn html_text(&self) -> Option<String> {
self.text()
.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> {
self.text()
.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> {
self.caption()
.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> {
self.caption()
.zip(self.caption_entities())
.map(|(text, entities)| Render::new(text, entities).as_markdown())
.map(|(text, entities)| Renderer::new(text, entities).as_markdown())
}
}