fix: hyphens in links
This commit is contained in:
parent
fe2e61118a
commit
46849ba66c
3 changed files with 22 additions and 4 deletions
|
@ -4,7 +4,7 @@ use std::collections::HashSet;
|
|||
|
||||
/// Render markdown input into HTML
|
||||
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();
|
||||
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 {
|
||||
// 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
|
||||
output.push_str(&format!("{buffer}\n"));
|
||||
output.push_str(&buffer);
|
||||
buffer.clear();
|
||||
}
|
||||
}
|
||||
|
@ -171,3 +171,19 @@ pub fn parse_alignment(input: &str) -> String {
|
|||
output.push_str(&buffer);
|
||||
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