mirror of
https://github.com/redlib-org/redlib.git
synced 2025-04-02 04:37:35 +03:00
* fix Code blocks https://github.com/redlib-org/redlib/issues/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 <matt@matthew.science>
This commit is contained in:
parent
c7f55c146a
commit
7770c57856
4 changed files with 36 additions and 1 deletions
19
Cargo.lock
generated
19
Cargo.lock
generated
|
@ -1302,6 +1302,24 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pulldown-cmark"
|
||||
version = "0.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f86ba2052aebccc42cbbb3ed234b8b13ce76f75c3551a303cb2bcffcff12bb14"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"memchr",
|
||||
"pulldown-cmark-escape",
|
||||
"unicase",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pulldown-cmark-escape"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae"
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.3"
|
||||
|
@ -1383,6 +1401,7 @@ dependencies = [
|
|||
"once_cell",
|
||||
"percent-encoding",
|
||||
"pretty_env_logger",
|
||||
"pulldown-cmark",
|
||||
"regex",
|
||||
"rinja",
|
||||
"route-recognizer",
|
||||
|
|
|
@ -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"
|
||||
|
|
10
src/utils.rs
10
src/utils.rs
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue