Skip to content

Commit

Permalink
refactor: update markdown rendering for extra features and remove 'pu…
Browse files Browse the repository at this point in the history
…re' markdown render mode
  • Loading branch information
Kremilly committed Jun 10, 2024
1 parent 50f6d8c commit 5fbfc3d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 44 deletions.
58 changes: 24 additions & 34 deletions src/prime_down/pd_extras.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use regex::Regex;

use crate::{
consts::global::Global,
utils::generate::Generate,
configs::settings::Settings,
regexp::regex_core::CoreRegExp,
};

Expand All @@ -12,42 +10,34 @@ pub struct PrimeDownExtras;
impl PrimeDownExtras {

pub fn gist(markdown: &str) -> String {
if Settings::get("render_markdown.mode", "STRING") == Global::APP_NAME {
let re = Regex::new(CoreRegExp::RENDER_EXTRA_GIST).unwrap();

let replaced_markdown = re.replace_all(markdown, |captures: &regex::Captures| {
let link = captures.get(1).unwrap().as_str();
format!("<script src='{}.js'></script>", link)
});

replaced_markdown.to_string()
} else {
markdown.to_string()
}
let re = Regex::new(CoreRegExp::RENDER_EXTRA_GIST).unwrap();

let replaced_markdown = re.replace_all(markdown, |captures: &regex::Captures| {
let link = captures.get(1).unwrap().as_str();
format!("<script src='{}.js'></script>", link)
});

replaced_markdown.to_string()
}

pub fn qrcode(markdown: &str) -> String {
if Settings::get("render_markdown.mode", "STRING") == Global::APP_NAME {
let re = Regex::new(CoreRegExp::RENDER_EXTRA_QRCODE).unwrap();

let replaced_markdown = re.replace_all(markdown, |captures: &regex::Captures| {
let link = captures.get(1).unwrap().as_str();
let size: u32 = captures.get(2).unwrap().as_str().parse().unwrap();

let qr_code_base64 = Generate::qrcode(link, size);
let link_qrcode = format!("data:image/png;base64,{}", qr_code_base64);
let re = Regex::new(CoreRegExp::RENDER_EXTRA_QRCODE).unwrap();

let replaced_markdown = re.replace_all(markdown, |captures: &regex::Captures| {
let link = captures.get(1).unwrap().as_str();
let size: u32 = captures.get(2).unwrap().as_str().parse().unwrap();

let qr_code_base64 = Generate::qrcode(link, size);
let link_qrcode = format!("data:image/png;base64,{}", qr_code_base64);

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

replaced_markdown.to_string()
} else {
markdown.to_string()
}
format!(
"<p class='qrcode'>
<img src='{}' alt='QR Code of {}' />
</p>", link_qrcode, link
)
});

replaced_markdown.to_string()
}

}
1 change: 0 additions & 1 deletion src/ui/emojis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ impl Emojis {

pub const HOME: &'static str = "🏠";
pub const CLOCK: &'static str = "⏰";
pub const TOOLS: &'static str = "🛠️";
pub const VERSION: &'static str = "📜";

pub const LOCKED: &'static str = "🔒";
Expand Down
10 changes: 1 addition & 9 deletions src/ui/ui_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,15 @@ impl UI {

pub fn header() {
if Settings::get("ui.show_header", "BOOLEAN") == true {
let render_md_mode;
let name = StrUtils::capitalize(Global::APP_NAME);
let standard_font = FIGfont::standard().unwrap();

if Settings::get("render_markdown.mode", "STRING") == Global::APP_NAME {
render_md_mode = format!("{}", name.cyan());
} else {
render_md_mode = format!("{}", "Vanilla".cyan());
}


if let Some(title) = standard_font.convert(&name) {
println!("{}", &title.to_string().bold().cyan());
println!("-------------------------------------------------------------------");
println!("{} Version: {}", Emojis::VERSION, Global::APP_VERSION.yellow());
println!("{} Homepage: {} • {}", Emojis::HOME, Global::APP_HOMEPAGE.blue(), Global::APP_AUTHOR.green());
println!("{} Started in: {}", Emojis::CLOCK, System::date_time().magenta());
println!("{} Render mode: {}", Emojis::TOOLS, render_md_mode);
println!("-------------------------------------------------------------------");
}
}
Expand Down

0 comments on commit 5fbfc3d

Please sign in to comment.