Repository: platers/obsidian-linter (ts)

Issue:
Colon in H1 invalidates YAML
I used some titles with colons (e.g., `#V02: A title`). 
The automatic insert in the yaml title as `title: V02: A title` results in an invalid yaml (reason: double colon).

Suggestion: Some characters may be filtered before inserting them in the yaml.

Edit: On a second thought, the titles could just be inserted in quotation marks. ;)

Pull request description:
Add fix to long titles
Fixes #185 

Patch:
diff --git a/src/utils.ts b/src/utils.ts
index a04a486..47956ed 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -194,5 +194,5 @@ export function loadYAML(yaml_text: string): any {
 }
 
 export function escapeYamlString(str: string): string {
-  return dump(str).slice(0, -1);
+  return dump(str, {lineWidth: -1}).slice(0, -1);
 }


Test patch:
diff --git a/src/test.ts b/src/test.ts
index d6e8994..86763f5 100644
--- a/src/test.ts
+++ b/src/test.ts
@@ -658,4 +658,19 @@ describe('YAML Title', () => {
 
     expect(rulesDict['yaml-title'].apply(before, {'Title Key': 'title'})).toBe(after);
   });
+
+  it('Does not insert line breaks for long title', () => {
+    const before = dedent`
+    # Very long title 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
+    `;
+
+    const after = dedent`
+    ---
+    title: Very long title 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
+    ---
+    # Very long title 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
+    `;
+
+    expect(rulesDict['yaml-title'].apply(before, {'Title Key': 'title'})).toBe(after);
+  });
 });