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

For compatibility with markdown generated by other MD editors, allow optional space between container tag and type #352

Closed
asimons04 opened this issue Apr 24, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@asimons04
Copy link

asimons04 commented Apr 24, 2024

Describe the bug

I'm trying to replace markdown-it with Magicdoc, and I'm running into compatibility issues with markdown generated by other editors for custom container types.

Most other clients in this ecosystem use markdown-it and a custom container to generate spoiler blocks. I've implemented a custom renderer for this in Magicdoc, and it works, but it's not compatible with markdown generated elsewhere due to the fact Magicdoc doesn't allow a space between the container tag and the type.

Example:

This works in MagicDoc:

:::spoiler Title
This is spoiler text that will be inside a details/summary block.
:::

This does not work:

::: spoiler Title
This is spoiler text that will be inside a details/summary block.
:::

The space between the ::: and type causes the type to not be picked up. I can deal with this on my end, but it has to interact with markdown generated by other clients which all utilize a space between the container tag and the type.

Looking at /packages/plugins/svelte-marked/src/lib/markdown/extensions/container.ts, there's a regex rule for detecting the container tags.

const rule = /^:::(?<type>[a-z0-9-]+)(?<options>.*)?\n(?<content>(?:.|\n)*)\n:::(?:\n|$)/i

I haven't built this patch into my project yet, but simulating it with RegExr shows allowing an optional space between the ::: and (?type<>... should allow both ::: type and :::type formats:

const rule = /^::: ?(?<type>[a-z0-9-]+)(?<options>.*)?\n(?<content>(?:.|\n)*)\n:::(?:\n|$)/i

Would there be any issue to update the container rule regex to account for an optional space?

Reproduction

Basically make an extension using the container extension and put a space between the container tag (:::) and the container type.

Logs

No response

System Info

System:
    OS: Linux 5.10 Alpine Linux
    CPU: (4) x64 Intel(R) Core(TM) i5-6600T CPU @ 2.70GHz
    Memory: 5.05 GB / 19.41 GB
    Container: Yes
    Shell: 1.36.1 - /bin/ash
  Binaries:
    Node: 20.5.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.8.0 - /usr/local/bin/npm

Severity

Blocking all usage of Magidoc

@asimons04 asimons04 added the bug Something isn't working label Apr 24, 2024
@asimons04
Copy link
Author

asimons04 commented Apr 24, 2024

It was completely blocking usage since spoiler tags are widely used, but I've worked around this by pre-processing the source input to replace ::: spoiler with :::spoiler. Seems to work. Unsure, though, how to change the severity level in the GH issue.

@pelletier197
Copy link
Collaborator

I don't see any issue if we allow for an optional space after the :::. Would you be willing to open a PR to support this ? I'll review it tomorrow.

@asimons04
Copy link
Author

Yeah, I should be able to later this evening. Thanks.

@pelletier197
Copy link
Collaborator

This is merged. For reference, the way I implemented it, only a single space is allowed, otherwise it won't parse. This will be released in the next version.

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