r4ai / remark-callout

A remark plugin to add obsidian style callouts to markdown
https://r4ai.github.io/remark-callout/
MIT License
4 stars 1 forks source link

Regex catches invalid syntax #115

Closed eikowagenknecht closed 1 month ago

eikowagenknecht commented 1 month ago

The regex allows some invalid syntax while Obsidian does not.

Allowed syntax that should not be allowed:

> [!note]title

> [!note]? title

My suggestion for the regex would be:

  const match = text.match(
    /^\[!(?<type>[^\]]+)?\](?<isFoldable>[+-])?(?: (?<title>.*))?$/
  );

I have a PR (including test cases) ready if you accept contributions.

eikowagenknecht commented 1 month ago

On a related note, Obsidian considers this not a callout:

>
> [!note]
> Note with an empty line before the callout

remark skips the first empty line unfortunately, so that it is not directly different from:

> [!note]
> Note with an empty line before the callout

But it can be caught using the position property. I can do a PR for this a well.

r4ai commented 1 month ago

Hi @eikowagenknecht!

It would be great to fix these differences in behavior with Obsidian. PRs are welcome!