rumdl 0.1.82

A fast Markdown linter written in Rust (Ru(st) MarkDown Linter)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
use rumdl_lib::rule::Rule;
use rumdl_lib::rules::MD044ProperNames;

#[test]
fn test_correct_names() {
    let names = vec!["JavaScript".to_string(), "TypeScript".to_string()];
    let rule = MD044ProperNames::new(names, true);
    let content = "# Guide to JavaScript and TypeScript\n\nJavaScript is awesome!";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();
    assert!(result.is_empty());
}

#[test]
fn test_incorrect_names() {
    let names = vec!["JavaScript".to_string(), "TypeScript".to_string()];
    let rule = MD044ProperNames::new(names, true);
    let content = "# Guide to javascript and typescript\n\njavascript is awesome!";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();
    assert_eq!(result.len(), 3);
    let fixed = rule.fix(&ctx).unwrap();
    assert_eq!(fixed, "# Guide to JavaScript and TypeScript\n\nJavaScript is awesome!");
}

#[test]
fn test_code_block_excluded() {
    let names = vec!["JavaScript".to_string()];
    let rule = MD044ProperNames::new(names, false); // false = skip code blocks
    let content = "# JavaScript Guide\n\n```javascript\nconst x = 'javascript';\n```";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();
    assert!(result.is_empty());
}

#[test]
fn test_code_block_included() {
    let names = vec!["JavaScript".to_string()];
    let rule = MD044ProperNames::new(names, true); // true = check code blocks
    let content = "# JavaScript Guide\n\n```javascript\nconst x = 'javascript';\n```";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();
    assert!(!result.is_empty(), "Should detect 'javascript' in the code block");
    let fixed = rule.fix(&ctx).unwrap();
    assert!(
        fixed.contains("const x = 'JavaScript';"),
        "Should replace 'javascript' with 'JavaScript' in code blocks"
    );
}

#[test]
fn test_indented_code_block() {
    let names = vec!["JavaScript".to_string()];
    let rule = MD044ProperNames::new(names, false); // false = skip code blocks
    let content = "# JavaScript Guide\n\n    const x = 'javascript';\n    console.log(x);";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();
    if !result.is_empty() {
        eprintln!("Test failed - found violations:");
        for warning in &result {
            eprintln!("  Line {}: {}", warning.line, warning.message);
        }
        eprintln!("Code blocks detected: {:?}", ctx.code_blocks);
        eprintln!("Content: {content:?}");
        let mut byte_pos = 0;
        for (i, line) in content.lines().enumerate() {
            eprintln!(
                "Line {}: byte_pos={}, in_code_block={}, content={:?}",
                i + 1,
                byte_pos,
                ctx.is_in_code_block_or_span(byte_pos),
                line
            );
            byte_pos += line.len() + 1;
        }
    }
    assert!(result.is_empty());
}

#[test]
fn test_multiple_occurrences() {
    let names = vec!["JavaScript".to_string(), "Node.js".to_string()];
    let rule = MD044ProperNames::new(names, true);
    let content = "javascript with nodejs\njavascript and nodejs again";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    // Add debug output
    println!("Number of warnings: {}", result.len());
    for (i, warning) in result.iter().enumerate() {
        println!(
            "Warning {}: Line {}, Column {}, Message: {}",
            i + 1,
            warning.line,
            warning.column,
            warning.message
        );
    }

    // The important part is that it finds the occurrences, the exact count may vary
    assert!(!result.is_empty(), "Should detect multiple improper names");

    let fixed = rule.fix(&ctx).unwrap();
    println!("Original content: '{content}'");
    println!("Fixed content: '{fixed}'");

    // More lenient assertions
    assert!(
        fixed.contains("JavaScript"),
        "Should replace 'javascript' with 'JavaScript'"
    );
    assert!(fixed.contains("Node.js"), "Should replace 'nodejs' with 'Node.js'");
}

#[test]
fn test_word_boundaries() {
    let names = vec!["Git".to_string()];
    let rule = MD044ProperNames::new(names, true);
    let content = "Using git and github with gitflow";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();
    assert_eq!(result.len(), 1); // Only "git" should be flagged, not "github" or "gitflow"
    let fixed = rule.fix(&ctx).unwrap();
    assert_eq!(fixed, "Using Git and github with gitflow");
}

#[test]
fn test_fix_multiple_on_same_line() {
    let names = vec!["Rust".to_string(), "Cargo".to_string()];
    let rule = MD044ProperNames::new(names, true);
    let content = "Using rust and cargo is fun. rust is fast.";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let fixed = rule.fix(&ctx).unwrap();
    assert_eq!(fixed, "Using Rust and Cargo is fun. Rust is fast.");
}

#[test]
fn test_fix_adjacent_to_markdown() {
    let names = vec!["Markdown".to_string()];
    let rule = MD044ProperNames::new(names, false); // false = skip code blocks
    let content = "*markdown* _markdown_ `markdown` [markdown](link)";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let fixed = rule.fix(&ctx).unwrap();
    // When code_blocks=false, inline code should not be fixed
    // Link TEXT should be corrected, link URLs should not
    assert_eq!(fixed, "*Markdown* _Markdown_ `markdown` [Markdown](link)");
}

#[test]
fn test_fix_with_dots() {
    let names = vec!["Node.js".to_string()];
    let rule = MD044ProperNames::new(names, true);
    let content = "Using node.js or sometimes nodejs.";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let fixed = rule.fix(&ctx).unwrap();
    assert_eq!(fixed, "Using Node.js or sometimes Node.js.");
}

#[test]
fn test_fix_code_block_included() {
    let names = vec!["Rust".to_string()];
    let rule = MD044ProperNames::new(names, true); // true = check code blocks
    let content = "```rust\nlet lang = \"rust\";\n```\n\nThis is rust code.";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let fixed = rule.fix(&ctx).unwrap();
    assert_eq!(fixed, "```rust\nlet lang = \"Rust\";\n```\n\nThis is Rust code.");
}

#[test]
fn test_code_fence_language_identifiers_preserved() {
    // Test that language identifiers in code fences are not modified
    let names = vec!["Rust".to_string(), "Python".to_string(), "JavaScript".to_string()];
    let rule = MD044ProperNames::new(names, true); // true = check code blocks

    let content = r#"```rust
// This is rust code
let rust = "rust";
```

```python
# This is python code
python = "python"
```

```javascript
// This is javascript code
const javascript = "javascript";
```"#;

    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let fixed = rule.fix(&ctx).unwrap();

    // Language identifiers should remain lowercase
    assert!(fixed.contains("```rust"), "rust identifier should stay lowercase");
    assert!(fixed.contains("```python"), "python identifier should stay lowercase");
    assert!(
        fixed.contains("```javascript"),
        "javascript identifier should stay lowercase"
    );

    // When code_blocks = true (check code blocks), content inside should be capitalized
    assert!(
        fixed.contains("let Rust = \"Rust\""),
        "Variable names should be capitalized"
    );
    assert!(
        fixed.contains("# This is Python code"),
        "Comments should be capitalized"
    );
    assert!(
        fixed.contains("Python = \"Python\""),
        "Variable names should be capitalized"
    );
    assert!(
        fixed.contains("const JavaScript = \"JavaScript\""),
        "Variable names should be capitalized"
    );
}

#[test]
fn test_tilde_fence_language_identifiers() {
    // Test with tilde fences
    let names = vec!["Ruby".to_string()];
    let rule = MD044ProperNames::new(names, true); // true = check code blocks

    let content = "~~~ruby\nputs 'ruby'\n~~~";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let fixed = rule.fix(&ctx).unwrap();

    assert!(
        fixed.contains("~~~ruby"),
        "Tilde fence identifier should stay lowercase"
    );
    assert!(fixed.contains("puts 'Ruby'"), "Content should be capitalized");
}

#[test]
fn test_fence_with_attributes() {
    // Test fences with additional attributes
    let names = vec!["JSON".to_string()];
    let rule = MD044ProperNames::new(names, true); // true = check code blocks

    let content = "```json {highlight: [2]}\n{\n  \"json\": \"value\"\n}\n```";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let fixed = rule.fix(&ctx).unwrap();

    assert!(
        fixed.contains("```json {highlight: [2]}"),
        "Fence with attributes preserved"
    );
    assert!(fixed.contains("\"JSON\""), "Content should be capitalized");
}

#[test]
fn test_mixed_fence_types() {
    // Test document with both fence types
    let names = vec!["Go".to_string()];
    let rule = MD044ProperNames::new(names, true);

    let content = "```go\nfmt.Println(\"go\")\n```\n\n~~~go\nfmt.Println(\"go\")\n~~~";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let fixed = rule.fix(&ctx).unwrap();

    assert!(fixed.contains("```go"), "Backtick fence preserved");
    assert!(fixed.contains("~~~go"), "Tilde fence preserved");
    assert_eq!(fixed.matches("\"Go\"").count(), 2, "Both contents capitalized");
}

#[test]
fn test_html_comments() {
    // Since the html_comments configuration is not accessible via the public API,
    // and the default is true (check HTML comments), we can test that behavior
    let names = vec!["JavaScript".to_string(), "TypeScript".to_string()];
    let rule = MD044ProperNames::new(names, true);
    let content = "# JavaScript Guide\n\n<!-- javascript and typescript are mentioned here -->\n\nJavaScript is great!";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    // By default (html_comments=true), it should detect names inside HTML comments
    assert_eq!(
        result.len(),
        2,
        "Should detect 'javascript' and 'typescript' in HTML comments by default"
    );

    let fixed = rule.fix(&ctx).unwrap();
    assert!(
        fixed.contains("<!-- JavaScript and TypeScript are mentioned here -->"),
        "Should fix names in HTML comments by default"
    );
}

#[test]
fn test_html_comments_backtick_code_skipped() {
    // Backtick-wrapped text in HTML comments should be treated as code
    // when code_blocks is false (the default for MD044ProperNames::new)
    let names = vec!["JavaScript".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- Use javascript here -->\n<!-- Use `javascript` here -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    // Line 3: "javascript" not in backticks -> flagged
    // Line 4: "javascript" in backticks -> skipped (treated as code)
    assert_eq!(
        result.len(),
        1,
        "Should only flag 'javascript' in non-backtick HTML comment, got: {result:?}",
    );
    assert_eq!(result[0].line, 3);
}

#[test]
fn test_html_comments_double_backtick_code_skipped() {
    let names = vec!["JavaScript".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- This is a ``javascript`` command. -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    // "javascript" inside double backticks should be skipped
    assert_eq!(
        result.len(),
        0,
        "Should skip name inside double backticks in HTML comment"
    );
}

#[test]
fn test_html_comments_unclosed_backtick_not_code() {
    let names = vec!["JavaScript".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- This is a `javascript command. -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    // Unclosed backtick should NOT be treated as code
    assert_eq!(result.len(), 1, "Unclosed backtick should not suppress the violation");
}

#[test]
fn test_html_comments_multiple_code_spans() {
    let names = vec!["JavaScript".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- `javascript` and `javascript` are both code -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    // Both occurrences are in backticks, should both be skipped
    assert_eq!(result.len(), 0, "Both backtick-wrapped occurrences should be skipped");
}

#[test]
fn test_html_comments_mixed_code_and_prose() {
    let names = vec!["JavaScript".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- javascript and `javascript` in same comment -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    // First "javascript" is NOT in backticks (flagged), second IS (skipped)
    assert_eq!(result.len(), 1, "Should only flag the non-backtick occurrence");
}

#[test]
fn test_regular_markdown_backticks_still_work() {
    // Ensure we didn't break regular markdown code span handling
    let names = vec!["JavaScript".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\nThis is javascript and `javascript` in backticks.";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    // "javascript" in regular text flagged, "javascript" in backticks skipped (by pulldown-cmark)
    assert_eq!(result.len(), 1, "Regular markdown backtick handling should still work");
}

#[test]
fn test_html_block_backtick_code_skipped() {
    // Backtick-wrapped text in HTML blocks should also be treated as code
    let names = vec!["JavaScript".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<div>\nUse javascript here and `javascript` in backticks.\n</div>";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    // "javascript" bare in HTML block -> flagged; in backticks -> skipped
    assert_eq!(
        result.len(),
        1,
        "Should only flag bare name in HTML block, not backtick-wrapped"
    );
}

#[test]
fn test_html_comments_backtick_code_blocks_true() {
    // When code_blocks = true, backtick-wrapped text should still be flagged
    // MD044ProperNames::new(names, true) sets code_blocks = true
    let names = vec!["JavaScript".to_string()];
    let rule = MD044ProperNames::new(names, true);
    let content = "# Heading\n\n<!-- Use `javascript` here -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    // code_blocks = true means check inside code too, so backticks don't help
    assert_eq!(
        result.len(),
        1,
        "With code_blocks=true, backtick-wrapped text should still be flagged"
    );
}

#[test]
fn test_html_comments_backtick_autofix() {
    // Autofix should fix bare names but leave backtick-wrapped names unchanged
    let names = vec!["JavaScript".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- Use javascript here and `javascript` in backticks. -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let fixed = rule.fix(&ctx).unwrap();

    // Bare "javascript" fixed to "JavaScript", backtick-wrapped left alone
    assert_eq!(
        fixed,
        "# Heading\n\n<!-- Use JavaScript here and `javascript` in backticks. -->"
    );
}

#[test]
fn test_html_comments_multiline_with_backticks() {
    // Multi-line HTML comment where backtick code is on an interior line
    let names = vec!["JavaScript".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!--\nUse javascript here.\nUse `javascript` as code.\n-->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    // Line 4: bare "javascript" -> flagged
    // Line 5: backtick-wrapped -> skipped
    assert_eq!(result.len(), 1, "Should only flag bare name in multi-line HTML comment");
    assert_eq!(result[0].line, 4);
}

#[test]
fn test_html_comments_inline_link_url_skipped() {
    // Issue #532: inline link URLs in HTML comments should not be flagged
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\nThis is a Test.\n\n<!-- For more information, see the [relevant page](test.md). -->\n<!-- For more information, see `test.md` -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    // Line 3: "Test" is already correct
    // Line 5: "test" in (test.md) is a URL -> skipped
    // Line 6: "test" in `test.md` is code -> skipped
    assert_eq!(
        result.len(),
        0,
        "Should not flag names inside link URLs in HTML comments. Got: {result:?}",
    );
}

#[test]
fn test_html_comments_inline_link_text_still_flagged() {
    // Link text IS prose and should be checked for proper names
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- See the [test page](docs.md) for details -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    // "test" in link text [test page] should still be flagged
    assert_eq!(
        result.len(),
        1,
        "Should flag improper name in link text within HTML comments. Got: {result:?}",
    );
}

#[test]
fn test_html_comments_multiple_inline_links() {
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- [a](test.md) and [b](test2.md) -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        0,
        "Should skip names in multiple link URLs. Got: {result:?}",
    );
}

#[test]
fn test_html_comments_link_with_title() {
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- [page](test.md \"test title\") -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    // Both "test" in URL and "test" in title are within the (...) portion
    assert_eq!(
        result.len(),
        0,
        "Should skip names in link URL with title. Got: {result:?}",
    );
}

#[test]
fn test_html_comments_relative_link_paths() {
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- See [page](../test/file.md) and [other](./test.md) -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        0,
        "Should skip names in relative link paths. Got: {result:?}",
    );
}

#[test]
fn test_html_block_inline_link_url_skipped() {
    // Same behavior in HTML blocks, not just comments
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<div>\nSee [relevant page](test.md) for details.\n</div>";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        0,
        "Should skip names in link URLs inside HTML blocks. Got: {result:?}",
    );
}

#[test]
fn test_regular_markdown_link_url_still_handled() {
    // Regular Markdown links (outside HTML comments) are handled by is_in_link()
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\nSee [relevant page](test.md) for details.";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        0,
        "Regular Markdown link URLs should still be skipped. Got: {result:?}",
    );
}

#[test]
fn test_html_comments_not_a_link() {
    // Bare text that looks like it could be a link part shouldn't be skipped
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- test is mentioned here -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        1,
        "Bare name in HTML comment should still be flagged. Got: {result:?}",
    );
}

#[test]
fn test_html_comments_inline_link_autofix() {
    // Autofix should fix link text but leave URL alone
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- See the [test page](test.md) -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let fixed = rule.fix(&ctx).unwrap();

    // "test" in link text should be fixed; "test" in URL should remain
    assert_eq!(fixed, "# Heading\n\n<!-- See the [Test page](test.md) -->",);
}

#[test]
fn test_html_comments_image_link_url_skipped() {
    // Image URLs in HTML comments should also be skipped
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- ![screenshot](test-screenshot.png) -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        0,
        "Should skip names in image URLs in HTML comments. Got: {result:?}",
    );
}

#[test]
fn test_html_comments_multiline_with_link() {
    // Multi-line HTML comment with inline link
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!--\nFor details, see [the guide](test.md).\n-->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        0,
        "Should skip names in link URLs in multi-line HTML comments. Got: {result:?}",
    );
}

#[test]
fn test_html_comments_link_with_nested_brackets() {
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- [see [this] page](test.md) -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        0,
        "Should handle nested brackets in link text and skip URL. Got: {result:?}",
    );
}

#[test]
fn test_html_comments_link_with_balanced_parens_in_url() {
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- [page](https://example.com/test_(section)) -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        0,
        "Should handle balanced parentheses in URLs. Got: {result:?}",
    );
}

#[test]
fn test_html_comments_reference_link_skipped() {
    // Reference-style links [text][ref] in HTML comments: ref portion should be skipped
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- See the [relevant page][test-ref] for details -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        0,
        "Should skip names in reference link labels in HTML comments. Got: {result:?}",
    );
}

#[test]
fn test_html_comments_reference_link_text_still_flagged() {
    // Reference link text IS prose and should be checked
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- See the [test page][ref] for details -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        1,
        "Should flag improper name in reference link text. Got: {result:?}",
    );
}

#[test]
fn test_html_comments_mixed_link_styles() {
    // Both inline and reference links in one comment
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- [page](test.md) and [other][test-ref] -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        0,
        "Should skip names in both inline and reference link URLs. Got: {result:?}",
    );
}

#[test]
fn test_frontmatter_inline_link_url_skipped() {
    // YAML frontmatter can contain markdown-like link syntax in values
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "---\ndescription: See [relevant page](test.md) for details\n---\n\n# Heading\n";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        0,
        "Should skip names in link URLs within frontmatter. Got: {result:?}",
    );
}

#[test]
fn test_frontmatter_link_text_still_flagged() {
    // Link text in frontmatter IS prose and should be checked
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "---\ndescription: See [test page](example.md) for details\n---\n\n# Heading\n";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        1,
        "Should flag improper name in link text within frontmatter. Got: {result:?}",
    );
}

#[test]
fn test_html_comments_double_escaped_bracket_link() {
    // \\[text](url) — the backslash is escaped, so [ starts a real link
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<!-- \\\\[page](test.md) -->";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        0,
        "Should skip names in link URLs even with double-escaped preceding backslash. Got: {result:?}",
    );
}

#[test]
fn test_html_block_reference_link_url_skipped() {
    // Reference link inside an HTML block
    let names = vec!["Test".to_string()];
    let rule = MD044ProperNames::new(names, false);
    let content = "# Heading\n\n<div>\n[relevant page][test-ref]\n</div>\n";
    let ctx = rumdl_lib::lint_context::LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
    let result = rule.check(&ctx).unwrap();

    assert_eq!(
        result.len(),
        0,
        "Should skip names in reference link labels in HTML blocks. Got: {result:?}",
    );
}