Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tryonkus opened this issue Aug 21, 2024 · 4 comments
Open

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

tryonkus opened this issue Aug 21, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@tryonkus
Copy link

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:

  • Remove the Strip YAML step from compilation (since the notes in my current project have no YAML, this works fine).
  • Change horizontal separators from --- to *** (also an easy fix, but I don't see a way to tell Obsidian to insert *** for a horizontal rule from the context menu).

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
Copy link

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
Copy link
Author

@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
Copy link

@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
Copy link
Author

Gotcha 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants