Repository: platers/obsidian-linter (ts)

Issue:
Linter Breaks the wikilinks on titles
Hi! I found an issue using the linter plugin, in some titles where I have a wiki link and then use the linter, and it replaces the wiki link.
Ex.
`# Fundamentals of [[Docker]]`
after the linter runs
`# Fundamentals of Placeholder_link 57849`
I run the linter and replaces `[[Docker]]` by `Placeholder_link 57849`

(Edited) Linter version 1.3.0

Pull request:
Fix Issue with First Letter Capitalization and Header
@platers 

Fixes #201 

It seems that when the placeholder is added to the title and capitalization is set to first letter capitalization, the header changes the placeholder to no longer be all caps which meant that the replace would not work. In order to fix this, I made the replace case insensitive.

Changes Made:
- Updated the replace to be case insensitive for the links
- Added a test to verify that links stay as they were in the headings

Please let me know if we want the test placed elsewhere or a different kind of test or fix to be used.

Patch:
diff --git a/src/utils.ts b/src/utils.ts
index 4e00f53..fd36d83 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -123,7 +123,9 @@ export function ignoreCodeBlocksYAMLAndLinks(text: string, func: (text: string)
 
   if (linkMatches) {
     for (const link of linkMatches) {
-      text = text.replace(linkPlaceHolder, link);
+      // Regex was added to fix capitalization issue  where another rule made the text not match the original place holder's case
+      // see https://github.com/platers/obsidian-linter/issues/201
+      text = text.replace(new RegExp(linkPlaceHolder, 'i'), link);
     }
   }
 


Test patch:
diff --git a/src/test.ts b/src/test.ts
index 6eb3489..c1586e1 100644
--- a/src/test.ts
+++ b/src/test.ts
@@ -721,4 +721,19 @@ describe('Links', () => {
 
     expect(rulesDict['trailing-spaces'].apply(before)).toBe(after);
   });
+  it('Link in heading is still present with first letter capitalization rules on', () => {
+    const before = dedent`
+    # Heading [[docker]]
+    # Heading [docker](docker)
+    # Heading ![docker](docker)
+    `;
+
+    const after = dedent`
+    # Heading [[docker]]
+    # Heading [docker](docker)
+    # Heading ![docker](docker)
+    `;
+
+    expect(rulesDict['capitalize-headings'].apply(before, {'Style': 'First Letter'})).toBe(after);
+  });
 });