kevboh / longform

A plugin for Obsidian that helps you write and edit novels, screenplays, and other long projects.
Other
671 stars 30 forks source link

Bug: YAML removal tool also removes consecutive horizontal rules #265

Open tryonkus opened 2 months ago

tryonkus commented 2 months ago

Versions Longform version: 2.0.7 Obsidian version: 1.6.7 OS [e.g. macOS, Windows, iOS, Android]: MacOS v14.6.1 Sonoma Theme: Minimal Other plugins that you think might be relevant here:

Describe the bug If I place a horizontal rule using three hyphens, some text, then another three hyphens, Longform will treat this as a YAML header and remove the rules and anything between them.

Current workarounds:

To Reproduce Steps to reproduce the behavior:

  1. In a Longform note, type some body text.
  2. Type "---" to create a horizontal rule in the text.
  3. Insert a blank line, type some more body text, then insert another blank line.
  4. Type "---" to create another horizontal rule
  5. Type more body text.
  6. Compile Longform manuscript
  7. Horizontal rules and the text between them will be missing from the compiled file.

Expected behavior If I place a horizontal rule using three hyphens, some text, then another three hyphens, Longform should treat these as rules rather than as a YAML header. Longform should recognize a "---" occurring after anything other than whitespace as a horizontal rule rather than YAML.

Screenshots none

Additional context Note: I'm seeing this behavior when compiling notes without YAML frontmatter, and it's possible that Longform would recognize the horizontal rules correctly if there was YAML present. I need to test this.

pjkaufman commented 2 months ago

I could be wrong, but removing the m flag on this line should fix the issue since it allows the first instance in a file no matter where it is to be matched. Obsidian only allows YAML to start a file.

tryonkus commented 2 months ago

@pjkaufman I'll need to look at that. I've been thinking about how to build a regex rule that ignores the --- in YAML headers, and turning off the m flag makes finding the first one easy—I just don't match at the beginning of the string. I've played with regex enough to believe there is a way to find the closing YAML ---, but I haven't dug deep enough yet to find it. I've done a fair bit of experimentation with regex in the past, but I'm far from expert.

If I'm sure to add blank lines before and after horizontal rules, that also makes finding them fairly easy, since I can search for \n\n before the rule to see if it's legit. I always set my own linting rules (and Linter) to add blank lines between markdown paragraphs, and if I run that first, it will be fairly simple to use the blank line rule to find horizontal rules. I'll let your (Linter's) logic add blank lines in the body but not the YAML, then take advantage of that in my regex rule. Depending on the order of operation, I may be able to use that in my Linter regex, since it will execute after the rest of the rules.

Make sense?

pjkaufman commented 2 months ago

@tryonkus , the comment I made was actual meant for the plugin's maintainer. It should fix the issue with finding the YAML for Longform without the need for any real change to the horizontal rules or the Linter.

tryonkus commented 2 months ago

Gotcha 👍🏻