Render html <code> tags as code in markdown (#3425)

pull/3839/head
A-Walrus 2 years ago committed by GitHub
parent ffb41a94f0
commit ac460ac837
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -178,6 +178,21 @@ impl Markdown {
.map(|key| get_theme(key)) .map(|key| get_theme(key))
.collect(); .collect();
// Transform text in `<code>` blocks into `Event::Code`
let mut in_code = false;
let parser = parser.filter_map(|event| match event {
Event::Html(tag) if *tag == *"<code>" => {
in_code = true;
None
}
Event::Html(tag) if *tag == *"</code>" => {
in_code = false;
None
}
Event::Text(text) if in_code => Some(Event::Code(text)),
_ => Some(event),
});
for event in parser { for event in parser {
match event { match event {
Event::Start(Tag::List(list)) => { Event::Start(Tag::List(list)) => {

Loading…
Cancel
Save