Skip to content

Commit 4b8d2cf

Browse files
authored
Merge pull request #105 from rodneylab/build__update_dependencies
build update dependencies
2 parents e3576d1 + 5e30f02 commit 4b8d2cf

File tree

10 files changed

+298
-106
lines changed

10 files changed

+298
-106
lines changed

Cargo.lock

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ html5ever = "0.29.0"
2626
js-sys = "0.3.69"
2727
mrml = { version = "4.0.1", features = ["parse", "render"], default-features = false }
2828
nom = { version = "7.1.3", features = ["alloc"] }
29-
pulldown-cmark = "0.9.2"
29+
pulldown-cmark = "0.10.3"
30+
pulldown-cmark-escape = "0.10.1"
3031
serde = { version = "1.0.215", features = ["derive"] }
3132
serde-wasm-bindgen = "0.6.5"
3233
textwrap = "0.16.1"

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
"wasmbuild": "deno run -A jsr:@deno/wasmbuild@0.17.3 --project=parsedown"
55
},
66
"exclude": ["lib/"],
7-
"imports": { "@std/assert": "jsr:@std/assert@^1.0.3" }
7+
"imports": { "@std/assert": "jsr:@std/assert@^1.0.8" }
88
}

lib/parsedown.generated.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// deno-fmt-ignore-file
55
/// <reference types="./parsedown.generated.d.ts" />
66

7-
// source-hash: 94b0ac08011ee053711880e7382330d1e6d84942
7+
// source-hash: 386c448320ef24975d9d36b44f28bba83b3508d3
88
let wasm;
99

1010
const heap = new Array(128).fill(undefined);

lib/parsedown_bg.wasm

14.2 KB
Binary file not shown.

src/inline_html/mod.rs

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
use nom::{
2+
branch::alt,
3+
bytes::complete::{is_not, tag},
4+
character::complete::{alphanumeric1, multispace0},
5+
combinator::recognize,
6+
multi::many1_count,
7+
sequence::{delimited, pair},
8+
IResult,
9+
};
10+
11+
#[derive(Debug, PartialEq, Eq, Hash)]
12+
#[non_exhaustive]
13+
pub enum InlineHTMLTagType {
14+
Opening(String),
15+
//SelfClosing,
16+
Closing(String),
17+
}
18+
19+
fn parse_html_tag_content(line: &str) -> IResult<&str, (&str, &str)> {
20+
let (remainder, tag_content) = is_not(">/")(line)?;
21+
let (attributes, (tag_name, _space)) = pair(
22+
recognize(many1_count(alt((alphanumeric1, tag("-"))))),
23+
multispace0,
24+
)(tag_content)?;
25+
Ok((remainder, (tag_name, attributes)))
26+
}
27+
28+
fn parse_closing_html_tag(line: &str) -> IResult<&str, (&str, &str, InlineHTMLTagType)> {
29+
let (remaining_line, (tag_name, tag_attributes)) =
30+
delimited(tag("</"), parse_html_tag_content, tag(">"))(line)?;
31+
Ok((
32+
remaining_line,
33+
(
34+
tag_name,
35+
tag_attributes,
36+
InlineHTMLTagType::Closing(tag_name.into()),
37+
),
38+
))
39+
}
40+
41+
fn parse_opening_html_tag(line: &str) -> IResult<&str, (&str, &str, InlineHTMLTagType)> {
42+
let (remaining_line, (tag_name, tag_attributes)) =
43+
delimited(tag("<"), parse_html_tag_content, tag(">"))(line)?;
44+
Ok((
45+
remaining_line,
46+
(
47+
tag_name,
48+
tag_attributes,
49+
InlineHTMLTagType::Opening(tag_name.into()),
50+
),
51+
))
52+
}
53+
54+
pub fn parse_node(html_node: &str) -> Option<InlineHTMLTagType> {
55+
match alt((parse_opening_html_tag, parse_closing_html_tag))(html_node) {
56+
Ok((_, (_, _, tag_type))) => Some(tag_type),
57+
Err(_) => None,
58+
}
59+
}
60+
61+
#[cfg(test)]
62+
mod tests {
63+
use super::{
64+
parse_closing_html_tag, parse_html_tag_content, parse_node, parse_opening_html_tag,
65+
InlineHTMLTagType,
66+
};
67+
68+
#[test]
69+
pub fn parse_html_tag_content_parses_valid_html_tag_without_attributes() {
70+
// arrange
71+
let tag_content = "abbr";
72+
73+
// act
74+
let result = parse_html_tag_content(tag_content);
75+
76+
// assert
77+
assert_eq!(result, Ok(("", ("abbr", ""))));
78+
}
79+
80+
#[test]
81+
pub fn parse_html_tag_content_parses_valid_html_tag_with_attributes() {
82+
// arrange
83+
let tag_content = r#"tool-tip inert role="tooltip""#;
84+
85+
// act
86+
let result = parse_html_tag_content(tag_content);
87+
88+
// assert
89+
assert_eq!(result, Ok(("", ("tool-tip", r#"inert role="tooltip""#))));
90+
}
91+
92+
#[test]
93+
pub fn parse_opening_html_tag_parses_valid_html_tag_without_attributes() {
94+
// arrange
95+
let tag = "<abbr>";
96+
97+
// act
98+
let result = parse_opening_html_tag(tag);
99+
100+
// assert
101+
assert_eq!(
102+
result,
103+
Ok((
104+
"",
105+
("abbr", "", InlineHTMLTagType::Opening(String::from("abbr")))
106+
))
107+
);
108+
}
109+
110+
#[test]
111+
pub fn parse_opening_html_tag_parses_valid_html_tag_with_attributes() {
112+
// arrange
113+
let tag = r#"<tool-tip inert role="tooltip">"#;
114+
115+
// act
116+
let result = parse_opening_html_tag(tag);
117+
118+
// assert
119+
assert_eq!(
120+
result,
121+
Ok((
122+
"",
123+
(
124+
"tool-tip",
125+
r#"inert role="tooltip""#,
126+
InlineHTMLTagType::Opening(String::from("tool-tip"))
127+
)
128+
))
129+
);
130+
}
131+
132+
#[test]
133+
pub fn parse_closing_html_tag_parses_valid_html_tag() {
134+
// arrange
135+
let tag = "</tool-tip>";
136+
137+
// act
138+
let result = parse_closing_html_tag(tag);
139+
140+
// assert
141+
assert_eq!(
142+
result,
143+
Ok((
144+
"",
145+
(
146+
"tool-tip",
147+
"",
148+
InlineHTMLTagType::Closing(String::from("tool-tip"))
149+
)
150+
))
151+
);
152+
}
153+
154+
#[test]
155+
pub fn parse_node_parses_valid_opening_html_tag() {
156+
// arrange
157+
let tag = "</tool-tip>";
158+
159+
// act
160+
let result = parse_node(tag);
161+
162+
// assert
163+
assert_eq!(
164+
result,
165+
Some(InlineHTMLTagType::Closing(String::from("tool-tip")))
166+
);
167+
}
168+
169+
#[test]
170+
pub fn parse_node_parses_valid_closing_html_tag() {
171+
// arrange
172+
let tag = r#"<tool-tip inert role="tooltip">"#;
173+
174+
// act
175+
let result = parse_node(tag);
176+
177+
// assert
178+
assert_eq!(
179+
result,
180+
Some(InlineHTMLTagType::Opening(String::from("tool-tip")))
181+
);
182+
}
183+
184+
#[test]
185+
pub fn parse_node_returns_none_for_invalid_html_tag() {
186+
// arrange
187+
let tag = "<tool-tip";
188+
189+
// act
190+
let result = parse_node(tag);
191+
192+
// assert
193+
assert_eq!(result, None);
194+
}
195+
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#![warn(clippy::all, clippy::pedantic)]
22

33
mod html_process;
4+
mod inline_html;
45
mod markdown;
56
mod url_utility;
7+
mod utilities;
68

79
use html_process::process_html;
810
use markdown::{

0 commit comments

Comments
 (0)