Skip to content

Commit 0e88c8a

Browse files
committed
Add support for italic text
1 parent 7ecf96a commit 0e88c8a

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/parser/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::utils::NotationMatching;
77
mod preprocessor;
88

99
/// The enum used to represent the distinct _raw_ values of a comment
10-
#[derive(Debug, Clone)]
10+
#[derive(Debug, Clone, Eq, PartialEq)]
1111
pub enum Value {
1212
/// The first [`String`] is the _notation_ found, and the second [`String`] are the _contents without the notation_
1313
Notation(String, String),
@@ -90,11 +90,19 @@ pub fn parse_bindgen(input: &str) -> Vec<StringType> {
9090
#[cfg(test)]
9191
mod tests {
9292
use crate::parser::parse_comment;
93+
use crate::parser::Value::Notation;
9394

9495
#[test]
9596
fn test() {
9697
let parsed = parse_comment("@param random Random thing lmao\n\n@block This is going to be\nA block of text\nThis is crazy right??\n\nHello this is not anotated\n");
98+
//println!("{:?}", parsed);
99+
}
100+
101+
#[test]
102+
fn italic_works() {
103+
let parsed = parse_comment("@brief \\a example \\\\e example 2 @em example 3");
97104
println!("{:?}", parsed);
105+
assert_eq!(parsed[0], Notation("@brief".to_owned(), "*example* *example* 2 *example* 3".to_owned()))
98106
}
99107
}
100108

src/parser/preprocessor.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,33 @@ use crate::utils::NotationMatching;
22

33
pub fn preprocess_line(input: &str) -> String {
44
render_code(
5-
make_refs_clickable(
6-
make_links_clickable(input).as_str()
5+
make_italic_text(
6+
make_refs_clickable(
7+
make_links_clickable(input).as_str()
8+
).as_str()
79
).as_str()
810
)
911
}
1012

13+
fn make_italic_text(input: &str) -> String {
14+
let mut apply_italic_to_next = false;
15+
input
16+
.split_whitespace()
17+
.map(|v| {
18+
if apply_italic_to_next {
19+
apply_italic_to_next = false;
20+
format!("*{}*", v)
21+
} else if v.contains_notation("a") || v.contains_notation("em") || v.contains_notation("e") {
22+
apply_italic_to_next = true;
23+
"".to_owned()
24+
} else {
25+
v.to_owned()
26+
}
27+
})
28+
.collect::<Vec<String>>()
29+
.join(" ")
30+
}
31+
1132
fn make_links_clickable(input: &str) -> String {
1233
input
1334
.split_whitespace()

0 commit comments

Comments
 (0)