Repository: platers/obsidian-linter (ts)

Issue:
Bug: Paste Seems to Mess with YAML Frontmatter
## Describe the Bug

I use a textexpander plain text snippet to create the yaml metadata. When the linter extension is enabled, the yaml is reformatted to invalid yaml even when linting is not run. I haven't been able to identify which linter setting is causing the issue, if that's the problem. 

- When I disable the Linter extension the behavior goes away (snippet works fine)
- I can type the metadata manually with no issue.
- I can use the snippet in another text editor with no issue
- I can use another program to create the snippet and have the same issue (for example, I can reproduce by adding the snippet to Raycast.

## How to Reproduce

Steps to reproduce the behavior:

1. Create a note in obsidian
2. Run a snippet or macro that outputs the yaml.
3. See error


Although the textexpander snippet has date variables, that isn't the cause of the problem. The snippet in Raycast is just this text, and the reformatting still happens:

```text
---
created: 
aliases: []
source: 
tags: []
updated: 
---
```

## Expected Behavior

A clear and concise description of what you expected to happen.

Expected output if applicable:

``` markdown
---
created: "2023-03-17"
aliases: []
source: 
tags: []
updated: "2023-03-17T11:51:50-0400"
---
```

## Actual behavior

The 3rd hyphen on the first line and new line are removed

```markdown
--created: "2023-03-17"
aliases: []
source: 
tags: []
updated: "2023-03-17T11:52:15-0400"
---
```

## Screenshots

If applicable, add screenshots to help explain your problem.

## Device

- [x] Desktop
- [ ] Mobile

## Additional Context

Add any other context about the problem here.
[data.json.zip](https://github.com/platers/obsidian-linter/files/11003381/data.json.zip)


Pull request description:
Fix for Removing First/Last Hyphen for YAML Frontmatter on Paste
Fixes #653 

Changes Made:
- Made sure that when removing hyphens it does not affect a hyphen then another hyphen
- Added a UT for the scenario in question

Patch:
diff --git a/src/rules/remove-hyphens-on-paste.ts b/src/rules/remove-hyphens-on-paste.ts
index 970af20..a4c919a 100644
--- a/src/rules/remove-hyphens-on-paste.ts
+++ b/src/rules/remove-hyphens-on-paste.ts
@@ -18,7 +18,7 @@ export default class RemoveHyphensOnPaste extends RuleBuilder<RemoveHyphensOnPas
     return RemoveHyphensOnPasteOptions;
   }
   apply(text: string, options: RemoveHyphensOnPasteOptions): string {
-    return text.replace(/(\S)[-‐]\s+\n?(?=\w)/g, '$1');
+    return text.replace(/([^\s-])[-‐]\s+\n?(?=\w)/g, '$1');
   }
   get exampleBuilders(): ExampleBuilder<RemoveHyphensOnPasteOptions>[] {
     return [


Test patch:
diff --git a/__tests__/remove-hyphens-on-paste.test.ts b/__tests__/remove-hyphens-on-paste.test.ts
new file mode 100644
index 0000000..aba70ff
--- /dev/null
+++ b/__tests__/remove-hyphens-on-paste.test.ts
@@ -0,0 +1,38 @@
+import RemoveHyphensOnPaste from '../src/rules/remove-hyphens-on-paste';
+import dedent from 'ts-dedent';
+import {ruleTest} from './common';
+
+ruleTest({
+  RuleBuilderClass: RemoveHyphensOnPaste,
+  testCases: [
+    { // accounts for https://github.com/platers/obsidian-linter/issues/653
+      testName: 'Make sure that hyphenated line breaks does not apply to YAML frontmatter on paste',
+      before: dedent`
+        ---
+        created: "2023-03-17"
+        aliases: []
+        source: 
+        tags: []
+        updated: "2023-03-17T11:51:50-0400"
+        ---
+        # Hello world
+        ${''}
+        Paragraph contents are here- [link text](pathToFile/file.md)
+        Paragraph contents are here- [[file]]
+      `,
+      after: dedent`
+        ---
+        created: "2023-03-17"
+        aliases: []
+        source: 
+        tags: []
+        updated: "2023-03-17T11:51:50-0400"
+        ---
+        # Hello world
+        ${''}
+        Paragraph contents are here- [link text](pathToFile/file.md)
+        Paragraph contents are here- [[file]]
+      `,
+    },
+  ],
+});