Skip to content

Commit

Permalink
refactor: update Markdown methods to use instance methods for improve…
Browse files Browse the repository at this point in the history
…d consistency
  • Loading branch information
Kremilly committed Jan 10, 2025
1 parent cbc7018 commit 44d689c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/cmd/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Tasks {
}

if let Some(contents) = contents {
Markdown::create(&contents, &line_url, &path).await?;
Markdown.create(&contents, &line_url, &path).await?;
}

Pdf::download_line(&line_url, url, path).await?;
Expand Down
8 changes: 4 additions & 4 deletions src/syntax/blocks/readme_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl ReadMeBlock {
.collect::<Vec<&str>>()
.join("\n");

let output = Markdown::append_extras_and_render(&unindented_markdown_block);
let output = Markdown.append_extras_and_render(&unindented_markdown_block);
Some(output)
} else {
None
Expand All @@ -68,7 +68,7 @@ impl ReadMeBlock {
pub async fn render_block_and_save_file(run: &str, flags: &Flags) {
if !flags.no_readme {
if let Some(markdown_html) = Self::render(run) {
let path = Markdown::get_filename_rendered(run);
let path = Markdown.get_filename_rendered(run);

if let Ok(contents) = Render::render_content(&run, markdown_html).await {
FileUtils.write_file(&path, contents);
Expand All @@ -85,12 +85,12 @@ impl ReadMeBlock {
if let Some(url) = Vars::get_readme(contents).await {
let get_last_part = &UrlMisc::get_last_part(&url);

let path = Markdown::get_filename_rendered(
let path = Markdown.get_filename_rendered(
&get_last_part.replace(".md", ".html")
);

let markdown_content = Remote::content(&url).await?;
let contents_extras = Markdown::append_extras_and_render(&markdown_content);
let contents_extras = Markdown.append_extras_and_render(&markdown_content);

if let Ok(contents) = Render::render_content(&get_last_part, contents_extras).await {
FileUtils.write_file(&path, contents);
Expand Down
10 changes: 5 additions & 5 deletions src/system/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Markdown {
}
}

pub fn get_filename_rendered(file: &str) -> String {
pub fn get_filename_rendered(&self, file: &str) -> String {
let filename = if Settings.get("render_markdown.overwrite", "BOOLEAN") == true {
".html".to_string()
} else {
Expand All @@ -59,15 +59,15 @@ impl Markdown {
RenderIO.get_file_path(file).replace(".html", &filename)
}

pub fn append_extras_and_render(markdown: &str) -> String {
pub fn append_extras_and_render(&self, markdown: &str) -> String {
let parser = Parser::new_ext(&markdown, Options::all());
let mut html_output = String::new();
html::push_html(&mut html_output, parser);

format!("<div class='markdown-content'>{}</div>", html_output)
}

pub async fn render(url: &str) -> Result<String, Box<dyn Error>> {
pub async fn render(&self, url: &str) -> Result<String, Box<dyn Error>> {
let markdown_content = Remote::content(url).await?;

let options = Options::empty();
Expand All @@ -79,9 +79,9 @@ impl Markdown {
Ok(html_output)
}

pub async fn create(contents: &str, url: &str, path: &str) -> Result<(), Box<dyn Error>> {
pub async fn create(&self, contents: &str, url: &str, path: &str) -> Result<(), Box<dyn Error>> {
if Remote::check_content_type(&url, "text/markdown").await? || url.contains(".md") {
let html_content = Self::render(url).await?;
let html_content = self.render(url).await?;
let content = RenderInject::html_content(contents, html_content).await?;

let original_name = FileNameRemote::new(url).get();
Expand Down

0 comments on commit 44d689c

Please sign in to comment.