NotePlan / plugins

The main NotePlan repository, which contains the source code for all NotePlan plugins. If a release entry has been created, it will be available for installation from within NotePlan application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

/add trigger fails for some existing frontmatter

jgclark opened this issue · comments

Checks

  • I confirm I have restarted NotePlan and this problem still persists.
  • Is this a repeatable problem?

Describe the bug
I've worked on this further and find that what's confusing one of the underlying helpers is the presence of this line in the frontmatter:

GitHub: [/add trigger command duplicates content · Issue #540 · NotePlan/plugins · GitHub](https://github.com/NotePlan/plugins/issues/540)

When it has that it shows several copies of this sort of error:

2024-04-26 22:56:21 | DEBUG | jgclark.NoteHelpers v0.19.1 :: addTriggerToNote('') starting ...
2024-04-26 22:56:23 ❗️ERROR❗️ Frontmatter getAttributes error. COULD NOT SANITIZE CONTENT: "unexpected end of the stream within a flow collection at line 7, column 1: <quotes note body>

If it is just this, then it works:

GitHub: https://github.com/NotePlan/plugins/issues/540

System

  • NotePlan: v3.11.1, but this goes back
  • NoteHelpers: v0.19.1, but this is due to underlying helpers

Additional context
I don't fully understand all the different helpers in NPFrontmatter.js, but the one I think needs attention is _fixFrontmatter(). I don't quite understand how it works -- where the quoted values are then used internally.

I have a added a few more tests to NPFrontmatter.test.js to show the issue.

When this is addressed, I would like to release a new version of NoteHelpers plugin.

@jgclark I don't see the tests you added. What branch?

Also can we have a brief chat about this? I'm still not 100% sure how to replicate and so don't know where to start

Sorry -- it didn't push up; it's now on main.
To replicate add the line referenced above to frontmatter, and then try to /add trigger.

@jgclark Interesting, so it appears that markdown links are illegal in YAML, and so that's why the fm library is choking on them. I have quoted them (using one of your handy regex helpers to find them) and it seems to be ok now. Your test passes and I added another test for the exact example in this ticket, which passes as well.

I rebuilt jgclark.NoteHelpers with this change and indeed it seems to /add the trigger leaving the previously choking markdown link in place which still works as a link. So I think we're good now. Thanks for finding/reporting this edge case.

Screen Cap 2024-05-04 at 14 53 02@2x

Please test see if this solves your issue. I am presumptively closing the ticket.