Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lychee-lib/src/extract/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ pub(crate) fn extract_markdown(input: &str, include_verbatim: bool) -> Vec<RawUr
// Wiki URL (`[[http://example.com]]`)
LinkType::WikiLink { has_pothole: _ } => {
inside_link_block = true;
//Ignore gitlab toc notation: https://docs.gitlab.com/user/markdown/#table-of-contents
if ["_TOC_".to_string(), "TOC".to_string()].contains(&dest_url.to_string()) {
return None;
}
Comment on lines +68 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but have you tried

if ["_TOC_", "TOC"].contains(&dest_url.as_str()) {

Would save a few allocs.

Copy link
Contributor Author

@JayJayArr JayJayArr May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds very good!
...but is apparently not stabilized yet: rust-lang/rust#130366
Is would be possible with as_ref like

if ["_TOC_", "TOC"].contains(&dest_url.as_ref()) {

but this might break in the future: rust-lang/rust#130366 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, you really did some soul-searching to dig this up. Nice research. ❤️
All good then.

Some(vec![RawUri {
text: dest_url.to_string(),
element: Some("a".to_string()),
Expand Down Expand Up @@ -421,4 +425,11 @@ $$
let uris = extract_markdown(markdown, true);
assert_eq!(uris, expected);
}

#[test]
fn test_ignore_gitlab_toc() {
let markdown = r"[[_TOC_]][TOC]";
let uris = extract_markdown(markdown, true);
assert!(uris.is_empty());
}
}