Skip to content

Commit

Permalink
add bold text check
Browse files Browse the repository at this point in the history
  • Loading branch information
KatyaRyazantseva authored and SamWilsn committed Aug 23, 2024
1 parent 9e4247b commit 82704cb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
11 changes: 7 additions & 4 deletions eipw-lint/src/lints/markdown/link_eip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ where
re,
slug,
link_depth: 0,
text_depth: 0,
current_link: Link {
url: String::new(),
text: String::new(),
Expand All @@ -55,6 +56,7 @@ struct Visitor<'a, 'b, 'c> {
re: Regex,
slug: &'c str,
link_depth: usize,
text_depth: usize,
current_link: Link,
}

Expand Down Expand Up @@ -91,7 +93,7 @@ impl<'a, 'b, 'c> Visitor<'a, 'b, 'c> {
};
let text_re = Regex::new(&dynamic_pattern).map_err(Error::custom)?;

if text_re.is_match(&self.current_link.text) {
if text_re.is_match(&self.current_link.text) && self.text_depth <= 1 {
return Ok(Next::TraverseChildren);
};

Expand Down Expand Up @@ -157,17 +159,18 @@ impl<'a, 'b, 'c> tree::Visitor for Visitor<'a, 'b, 'c> {
Ok(Next::TraverseChildren)
}

fn depart_link(&mut self, _: &Ast, _: &NodeLink) -> Result<(), Self::Error> {
fn depart_link(&mut self, ast: &Ast, _: &NodeLink) -> Result<(), Self::Error> {
if self.link_depth > 0 {
self.check(ast)?;
self.link_depth -= 1;
}
Ok(())
}

fn enter_text(&mut self, ast: &Ast, txt: &str) -> Result<Next, Self::Error> {
if self.link_depth > 0 {
self.current_link.text = txt.to_owned();
self.check(ast)?;
self.text_depth += 1;
self.current_link.text.push_str(txt);
}
Ok(Next::SkipChildren)
}
Expand Down
18 changes: 16 additions & 2 deletions eipw-lint/tests/lint_markdown_link_eip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,14 @@ header: value1
.await
.unwrap()
.into_inner();
assert_ne!(reports, "");
assert_eq!(reports,
r#"error[markdown-link-eip]: link text does not match link destination
|
4 | [EIP-1**EIP-1**](./eip-1.md)
|
= help: use `[EIP-1](./eip-1.md)` instead
"#
);
}

#[tokio::test]
Expand All @@ -169,7 +176,14 @@ header: value1
.await
.unwrap()
.into_inner();
assert_ne!(reports, "");
assert_eq!(reports,
r#"error[markdown-link-eip]: link text does not match link destination
|
4 | [EIP-1: eip motivation**EIP-1: eip motivation**](./eip-1.md#eip-motivation)
|
= help: use `[EIP-1: Eip motivation](./eip-1.md#eip-motivation)` instead
"#
);
}

#[tokio::test]
Expand Down

0 comments on commit 82704cb

Please sign in to comment.