Repository: platers/obsidian-linter (ts)

Issue:
Move Footnotes to the bottom: inserts extra 2 blank lines every time you run it
Move Footnotes to the bottom keeps adding an extra two blank line above the footnotes each time you run Linter.

Before:
```
A sentence about stuff.[^1]

[^1]: A reference about stuff.
```
  
After first run of Linter:
```
A sentence about stuff.[^1]



[^1]: A reference about stuff.
```

After second run of Linter:
```
A sentence about stuff.[^1]





[^1]: A reference about stuff.
```

After third run of Linter:

```
A sentence about stuff.[^1]







[^1]: A reference about stuff.
```

And so on. Thanks for your help!
Laura

Pull request:
Fix Footnote Whitespace
@platers 

This change fixes #174 .

This PR currently lists the changes for both it #202 . Please merge that PR first before doing anything with this PR. 

Changes Made:
- Made sure to strip whitespace off the end of the text prior to adding footnotes if any exist
- Added a test to make sure no newline is added when all footnotes are already in place.

Please let me know if we would like to change anything about the fix.

Patch:
diff --git a/src/utils.ts b/src/utils.ts
index 4e00f53..d6ef045 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -86,7 +86,7 @@ export function moveFootnotesToEnd(text: string) {
 
   // Add the footnotes to the end of the document
   if (footnotes.length > 0) {
-    text += '\n';
+    text = text.trimEnd() + '\n';
   }
   for (const footnote of footnotes) {
     text += '\n' + footnote;
@@ -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..c223459 100644
--- a/src/test.ts
+++ b/src/test.ts
@@ -473,8 +473,6 @@ describe('Move Footnotes to the bottom', () => {
 
    Prima prompta partiendo ius ne. Modo omnes neglegentur cu vel, nisl illum vel ex. Mel et vocent scribentur.[^41]
 
-
-
    [^1]: See @JIPPChristKingPaul2015, 50.
    [^2]: Jipp in -@JIPPChristKingPaul2015, 45, says, “Sale populo petentium vel eu, eam in alii novum voluptatum, te lorem postulant has”.
    [^3]: This is from Journal article --@gaventaLouisMartynGalatians2000, 99.
@@ -491,6 +489,19 @@ describe('Move Footnotes to the bottom', () => {
    `;
     expect(rulesDict['move-footnotes-to-the-bottom'].apply(before)).toBe(after);
   });
+  it('Footnote already at the bottom does not add an extra newline', () => {
+    const before = dedent`
+    Line
+
+    [^alpha]: bravo and charlie.
+    `;
+    const after = dedent`
+    Line
+
+    [^alpha]: bravo and charlie.
+    `;
+    expect(rulesDict['move-footnotes-to-the-bottom'].apply(before)).toBe(after);
+  });
 });
 describe('yaml timestamp', () => {
   it('Doesnt add date created if already there', () => {
@@ -721,4 +732,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);
+  });
 });