fix: hyphens in links
This commit is contained in:
parent
fe2e61118a
commit
46849ba66c
3 changed files with 22 additions and 4 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -3353,13 +3353,14 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tetratto-shared"
|
name = "tetratto-shared"
|
||||||
version = "12.0.2"
|
version = "12.0.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ammonia",
|
"ammonia",
|
||||||
"chrono",
|
"chrono",
|
||||||
"hex_fmt",
|
"hex_fmt",
|
||||||
"pulldown-cmark",
|
"pulldown-cmark",
|
||||||
"rand 0.9.1",
|
"rand 0.9.1",
|
||||||
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
"sha2",
|
"sha2",
|
||||||
"snowflaked",
|
"snowflaked",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tetratto-shared"
|
name = "tetratto-shared"
|
||||||
description = "Shared stuff for Tetratto"
|
description = "Shared stuff for Tetratto"
|
||||||
version = "12.0.2"
|
version = "12.0.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
repository.workspace = true
|
repository.workspace = true
|
||||||
|
@ -13,6 +13,7 @@ chrono = "0.4.41"
|
||||||
hex_fmt = "0.3.0"
|
hex_fmt = "0.3.0"
|
||||||
pulldown-cmark = "0.13.0"
|
pulldown-cmark = "0.13.0"
|
||||||
rand = "0.9.1"
|
rand = "0.9.1"
|
||||||
|
regex = "1.11.1"
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
sha2 = "0.10.9"
|
sha2 = "0.10.9"
|
||||||
snowflaked = "1.0.3"
|
snowflaked = "1.0.3"
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::collections::HashSet;
|
||||||
|
|
||||||
/// Render markdown input into HTML
|
/// Render markdown input into HTML
|
||||||
pub fn render_markdown(input: &str, proxy_images: bool) -> String {
|
pub fn render_markdown(input: &str, proxy_images: bool) -> String {
|
||||||
let input = &parse_alignment(input);
|
let input = &autolinks(&parse_alignment(input));
|
||||||
|
|
||||||
let mut options = Options::empty();
|
let mut options = Options::empty();
|
||||||
options.insert(Options::ENABLE_STRIKETHROUGH);
|
options.insert(Options::ENABLE_STRIKETHROUGH);
|
||||||
|
@ -102,7 +102,7 @@ fn parse_alignment_line(line: &str, output: &mut String, buffer: &mut String, is
|
||||||
if !is_alignment_waiting {
|
if !is_alignment_waiting {
|
||||||
// we need to go ahead and push/clear the buffer so we don't capture the stuff that came before this
|
// we need to go ahead and push/clear the buffer so we don't capture the stuff that came before this
|
||||||
// this only needs to be done on the first of these for a single alignment block
|
// this only needs to be done on the first of these for a single alignment block
|
||||||
output.push_str(&format!("{buffer}\n"));
|
output.push_str(&buffer);
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,3 +171,19 @@ pub fn parse_alignment(input: &str) -> String {
|
||||||
output.push_str(&buffer);
|
output.push_str(&buffer);
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adapted from <https://git.cypr.io/oz/autolink-rust>.
|
||||||
|
pub fn autolinks(input: &str) -> String {
|
||||||
|
if input.len() == 0 {
|
||||||
|
return String::new();
|
||||||
|
}
|
||||||
|
|
||||||
|
let pattern = regex::Regex::new(
|
||||||
|
r"(?ix)\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
pattern
|
||||||
|
.replace_all(input, "<a href=\"$0\">$0</a>")
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue