fix: markdown autolinking with images
This commit is contained in:
parent
46849ba66c
commit
c757ddb77a
3 changed files with 7 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "tetratto-shared"
|
||||
description = "Shared stuff for Tetratto"
|
||||
version = "12.0.3"
|
||||
version = "12.0.4"
|
||||
edition = "2024"
|
||||
authors.workspace = true
|
||||
repository.workspace = true
|
||||
|
|
|
@ -173,17 +173,20 @@ pub fn parse_alignment(input: &str) -> String {
|
|||
}
|
||||
|
||||
/// 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 {
|
||||
if input.len() == 0 {
|
||||
return String::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();
|
||||
|
||||
pattern
|
||||
.replace_all(input, "<a href=\"$0\">$0</a>")
|
||||
.replace_all(input, "<a href=\"$0\">$0</a> ")
|
||||
.to_string()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue