magidoc icon indicating copy to clipboard operation
magidoc copied to clipboard

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

Open asimons04 opened this issue 1 year ago • 3 comments
trafficstars

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 avatar Apr 24 '24 12:04 asimons04

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.

asimons04 avatar Apr 24 '24 12:04 asimons04

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.

pelletier197 avatar Apr 24 '24 13:04 pelletier197

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

asimons04 avatar Apr 24 '24 13:04 asimons04

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.

pelletier197 avatar May 04 '24 01:05 pelletier197