Skip to content

Commit

Permalink
fix(markdown): avoid false positive with markdown images
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnychevalier committed Aug 5, 2024
1 parent 2e9b89d commit c3c79a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Fixed

- Markdown: avoid false positives with images (e.g., `![image](image.png)`)

[Unreleased]: https://github.com/ronnychevalier/typope/compare/v0.1.0...HEAD

## [0.1.0] - 04-08-2024
Expand Down
18 changes: 17 additions & 1 deletion src/lang/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ impl<'t> Iterator for IterMarkdown<'t> {
if !self.tree_sitter_types.contains(&kind) {
continue;
}
let node = node.ignore_children_ranges(|node| node.kind() == "code_span");
let node =
node.ignore_children_ranges(|node| ["code_span", "image"].contains(&node.kind()));

return Some(node);
}
Expand Down Expand Up @@ -156,4 +157,19 @@ hello
]
);
}

#[test]
fn image() {
let markdown = r#"abc ![link](link)"#;
let markdown = SharedSource::new("file.md", markdown.as_bytes().to_vec());
let mut parsed = Language::markdown().parse(&markdown).unwrap();
let strings = parsed.strings(markdown.as_ref()).collect::<Vec<_>>();
assert_eq!(
strings,
[LintableString {
offset: 0,
value: "abc ".into()
},]
);
}
}

0 comments on commit c3c79a6

Please sign in to comment.