fix: markdown autolinking with images

This commit is contained in:
trisua 2025-07-20 16:41:50 -04:00
parent 46849ba66c
commit c757ddb77a
3 changed files with 7 additions and 4 deletions

2
Cargo.lock generated
View file

@ -3353,7 +3353,7 @@ dependencies = [
[[package]] [[package]]
name = "tetratto-shared" name = "tetratto-shared"
version = "12.0.3" version = "12.0.4"
dependencies = [ dependencies = [
"ammonia", "ammonia",
"chrono", "chrono",

View file

@ -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.3" version = "12.0.4"
edition = "2024" edition = "2024"
authors.workspace = true authors.workspace = true
repository.workspace = true repository.workspace = true

View file

@ -173,17 +173,20 @@ pub fn parse_alignment(input: &str) -> String {
} }
/// Adapted from <https://git.cypr.io/oz/autolink-rust>. /// Adapted from <https://git.cypr.io/oz/autolink-rust>.
///
/// The only real change here is that autolinks require a whitespace OR end the
/// end of the pattern to match here.
pub fn autolinks(input: &str) -> String { pub fn autolinks(input: &str) -> String {
if input.len() == 0 { if input.len() == 0 {
return String::new(); return String::new();
} }
let pattern = regex::Regex::new( let pattern = regex::Regex::new(
r"(?ix)\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))", r"(?ix)\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))(\s|$)",
) )
.unwrap(); .unwrap();
pattern pattern
.replace_all(input, "<a href=\"$0\">$0</a>") .replace_all(input, "<a href=\"$0\">$0</a> ")
.to_string() .to_string()
} }