Skip to content

Commit

Permalink
fix Code blocks err #227 (#323)
Browse files Browse the repository at this point in the history
* fix Code blocks #227

* add pulldown-cmark

* add pulldown-cmark

* fix Code blocks err #227

* add pre style for post codeblock

* Update style.css (fix Code blocks err #227 )

---------

Co-authored-by: Matthew Esposito <[email protected]>
  • Loading branch information
freedit-dev and sigaloid authored Feb 3, 2025
1 parent c7f55c1 commit 7770c57
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ rss = "2.0.7"
arc-swap = "1.7.1"
serde_json_path = "0.7.1"
async-recursion = "1.1.1"
pulldown-cmark = { version = "0.12.0", features = ["simd", "html"], default-features = false }
common-words-all = { version = "0.0.2", default-features = false, features = ["english", "one"] }
hyper-rustls = { version = "0.24.2", features = [ "http2" ] }
tegen = "0.1.4"
Expand Down
10 changes: 9 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,15 @@ pub async fn parse_post(post: &Value) -> Post {
get_setting("REDLIB_PUSHSHIFT_FRONTEND").unwrap_or_else(|| String::from(crate::config::DEFAULT_PUSHSHIFT_FRONTEND)),
)
} else {
rewrite_urls(&val(post, "selftext_html"))
let selftext = val(post, "selftext");
if selftext.contains("```") {
let mut html_output = String::new();
let parser = pulldown_cmark::Parser::new(&selftext);
pulldown_cmark::html::push_html(&mut html_output, parser);
rewrite_urls(&html_output)
} else {
rewrite_urls(&val(post, "selftext_html"))
}
};

// Build a post using data parsed from Reddit post API
Expand Down
7 changes: 7 additions & 0 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,13 @@ a.search_subreddit:hover {
overflow-wrap: anywhere;
}

.post_body pre {
background: var(--background);
overflow-x: auto;
margin: 10px 0;
padding: 10px;
}

.post_body img {
max-width: 100%;
display: block;
Expand Down

0 comments on commit 7770c57

Please sign in to comment.