Skip to content

Commit

Permalink
refactor: remove RenderExtras methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Kremilly committed Sep 8, 2024
1 parent 5b58c2b commit ae6cc92
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 76 deletions.
24 changes: 0 additions & 24 deletions src/generator/qr_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use image::{
ImageFormat,
};

use crate::utils::base64::Base64;

pub struct GenQrCode {
link: String,
size: u32,
Expand All @@ -28,28 +26,6 @@ impl GenQrCode {
}
}

pub fn get(&self) -> String {
let code = QrCode::new(self.link.as_str()).unwrap();
let image = code.render::<Luma<u8>>().max_dimensions(self.size, self.size).build();

let mut img_bytes = Vec::new();
let mut cursor = Cursor::new(&mut img_bytes);
image.write_to(&mut cursor, ImageFormat::Png).unwrap();

let qr_code = Base64::encode(img_bytes);
format!("data:image/png;base64,{}", qr_code)
}

pub fn html(&self) -> String {
let qr_code_base64 = self.get();

format!(
"<p class='qrcode'>
<img src='{}' alt='QR Code of {}' />
</p>", qr_code_base64, self.link
)
}

pub fn png(&self, file_path: &str) -> Result<(), Box<dyn Error>> {
let code = QrCode::new(self.link.as_str())?;
let image = code.render::<Luma<u8>>().max_dimensions(
Expand Down
3 changes: 0 additions & 3 deletions src/regexp/regex_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ impl CoreRegExp {
pub const EXTRACT_URL: &'static str = r"(?P<url>https?://[^\s]+)";
pub const VALIDATE_TAGS: &'static str = r".*\*{1,2}.*|.*_.*|.*<\s*[a-zA-Z]+[^>]*>.*";

pub const RENDER_EXTRA_GIST: &'static str = r#"\[!extra gist data=['"](.*?)['"]\]"#;
pub const RENDER_EXTRA_QRCODE: &'static str = r#"\[!extra qrcode data=['"](.*?)['"], size=(\d+)\]"#;

pub const CLEAN_LINE: &'static str = r"\s*\{\s*\}\s*";

}
5 changes: 1 addition & 4 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ pub mod render;
pub mod render_io;

// Helpers
pub mod render_inject;

// Extras
pub mod render_extras;
pub mod render_inject;
36 changes: 0 additions & 36 deletions src/render/render_extras.rs

This file was deleted.

6 changes: 1 addition & 5 deletions src/system/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::{
render::{
render_io::RenderIO,
render_inject::RenderInject,
render_extras::RenderExtras,
},

utils::{
Expand Down Expand Up @@ -61,10 +60,7 @@ impl Markdown {
}

pub fn append_extras_and_render(markdown: &str) -> String {
let markdown_block_extras_qrcode = RenderExtras::qrcode(&markdown);
let markdown_block_extras_gist = RenderExtras::gist(&markdown_block_extras_qrcode);

let parser = Parser::new_ext(&markdown_block_extras_gist, Options::all());
let parser = Parser::new_ext(&markdown, Options::all());
let mut html_output = String::new();
html::push_html(&mut html_output, parser);

Expand Down
4 changes: 0 additions & 4 deletions src/utils/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ pub struct Base64;

impl Base64 {

pub fn encode(input: Vec<u8>) -> String {
BASE64_STANDARD.encode(input)
}

pub fn encode_html(content: &str) -> String {
format!(
"data:text/html;base64,{}", BASE64_STANDARD.encode(content)
Expand Down

0 comments on commit ae6cc92

Please sign in to comment.