Skip to content

Commit

Permalink
fix emojis being replaced in code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Jun 4, 2023
1 parent 2f86452 commit 464b022
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flash"
version = "0.2.9"
version = "0.2.10"
edition = "2021"
authors = ["HJfod"]
description = "Documentation generator for C++"
Expand Down
21 changes: 18 additions & 3 deletions src/builder/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct MDStream<'i, 'c, 'b, 'e, const SIZE: usize, F: Fn(UrlPath) -> Option<UrlP
builder: &'b Builder<'e>,
metadata: Option<Metadata>,
insert_para_stage: InsertP,
inside_code_block: bool,
}

impl<
Expand All @@ -98,6 +99,7 @@ impl<
builder,
metadata,
insert_para_stage: InsertP::Dont,
inside_code_block: false,
}
}
}
Expand Down Expand Up @@ -126,9 +128,14 @@ impl<
return None;
};
Some(match event {
Event::Text(t) => Event::Text(CowStr::Boxed(Box::from(
fmt_emoji(&t).as_str()
))),
// Don't format emojis inside code blocks lol
Event::Text(t) => if self.inside_code_block {
Event::Text(t)
} else {
Event::Text(CowStr::Boxed(Box::from(
fmt_emoji(&t).as_str()
)))
}
Event::Start(tag) => Event::Start(match tag {
// Fix urls to point to root
Tag::Link(ty, ref dest, ref title) | Tag::Image(ty, ref dest, ref title) => {
Expand Down Expand Up @@ -213,6 +220,10 @@ impl<
}
Tag::Heading(lvl, frag, classes)
}
Tag::CodeBlock(b) => {
self.inside_code_block = true;
Tag::CodeBlock(b)
}
_ => tag
}),
Event::End(tag) => Event::End(match tag {
Expand All @@ -225,6 +236,10 @@ impl<
}
Tag::Heading(lvl, frag, classes)
}
Tag::CodeBlock(b) => {
self.inside_code_block = false;
Tag::CodeBlock(b)
}
_ => tag
}),
_ => event,
Expand Down

0 comments on commit 464b022

Please sign in to comment.