mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-22 19:41:03 +00:00
parent
458baf5f78
commit
e6bdeb7c4b
1 changed files with 17 additions and 7 deletions
|
@ -223,7 +223,15 @@ pub fn md_to_html<'a>(
|
||||||
.map(|evt| process_image(evt, inline, &media_processor))
|
.map(|evt| process_image(evt, inline, &media_processor))
|
||||||
// Ignore headings, images, and tables if inline = true
|
// Ignore headings, images, and tables if inline = true
|
||||||
.scan((vec![], inline), inline_tags)
|
.scan((vec![], inline), inline_tags)
|
||||||
.map(|evt| match evt {
|
.scan(false, |in_code, evt| match evt {
|
||||||
|
Event::Start(Tag::CodeBlock(_)) | Event::Start(Tag::Code) => {
|
||||||
|
*in_code = true;
|
||||||
|
Some((vec![evt], vec![], vec![]))
|
||||||
|
}
|
||||||
|
Event::End(Tag::CodeBlock(_)) | Event::End(Tag::Code) => {
|
||||||
|
*in_code = false;
|
||||||
|
Some((vec![evt], vec![], vec![]))
|
||||||
|
}
|
||||||
Event::Text(txt) => {
|
Event::Text(txt) => {
|
||||||
let (evts, _, _, _, new_mentions, new_hashtags) = txt.chars().fold(
|
let (evts, _, _, _, new_mentions, new_hashtags) = txt.chars().fold(
|
||||||
(vec![], State::Ready, String::new(), 0, vec![], vec![]),
|
(vec![], State::Ready, String::new(), 0, vec![], vec![]),
|
||||||
|
@ -292,7 +300,7 @@ pub fn md_to_html<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
State::Ready => {
|
State::Ready => {
|
||||||
if c == '@' {
|
if !*in_code && c == '@' {
|
||||||
events.push(Event::Text(text_acc.into()));
|
events.push(Event::Text(text_acc.into()));
|
||||||
(
|
(
|
||||||
events,
|
events,
|
||||||
|
@ -302,7 +310,7 @@ pub fn md_to_html<'a>(
|
||||||
mentions,
|
mentions,
|
||||||
hashtags,
|
hashtags,
|
||||||
)
|
)
|
||||||
} else if c == '#' {
|
} else if !*in_code && c == '#' {
|
||||||
events.push(Event::Text(text_acc.into()));
|
events.push(Event::Text(text_acc.into()));
|
||||||
(
|
(
|
||||||
events,
|
events,
|
||||||
|
@ -347,9 +355,9 @@ pub fn md_to_html<'a>(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
(evts, new_mentions, new_hashtags)
|
Some((evts, new_mentions, new_hashtags))
|
||||||
}
|
}
|
||||||
_ => (vec![evt], vec![], vec![]),
|
_ => Some((vec![evt], vec![], vec![])),
|
||||||
})
|
})
|
||||||
.fold(
|
.fold(
|
||||||
(vec![], vec![], vec![]),
|
(vec![], vec![], vec![]),
|
||||||
|
@ -389,6 +397,8 @@ mod tests {
|
||||||
(" @spaces ", vec!["spaces"]),
|
(" @spaces ", vec!["spaces"]),
|
||||||
("@is_a@mention", vec!["is_a@mention"]),
|
("@is_a@mention", vec!["is_a@mention"]),
|
||||||
("not_a@mention", vec![]),
|
("not_a@mention", vec![]),
|
||||||
|
("`@helo`", vec![]),
|
||||||
|
("```\n@hello\n```", vec![]),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (md, mentions) in tests {
|
for (md, mentions) in tests {
|
||||||
|
|
Loading…
Reference in a new issue