executablebooks / mdformat

CommonMark compliant Markdown formatter
https://mdformat.rtfd.io
MIT License
402 stars 45 forks source link

mdformat breaks Hugo shortcodes by escaping `<` #402

Open jamesbraza opened 1 year ago

jamesbraza commented 1 year ago

Describe the bug

context

Running mdformat on a Markdown file with a Hugo shortcode.

expectation

I expected mdformat to not break the shortcode.

bug

Instead mdformat is breaking the shortcode by escaping < to \<.

problem

This breaks the shortcode for Hugo users.

Relevant Hugo comment: https://github.com/executablebooks/mdformat/issues/112#issuecomment-1148935498

Reproduce the bug

{{< youtube -dJolYw8tnk >}}

That links to this YouTube video. mdformat corrects this to

{{\< youtube -dJolYw8tnk >}}

List your environment

mdformat==0.7.16
mdformat-frontmatter==2.0.1
welcome[bot] commented 1 year ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

Oliver-Habersetzer commented 11 months ago

I agree this can be annoying. Also "[" and "]" are escaped - so I can't use this for Obsidian. I might make a PR so we're able to configure this behavior.

BartKeulen commented 9 months ago

I just want to add another case. I am using mkdocs with PyMarkdown Extension Snippets; useful for embedding content directly in your documentation pages.

A document is included using the following syntax:

--8<-- "filename.ext"

mdformat changes it to:

--8\<-- "filename.ext"

The behavior does not happen inside a code block, the following code is not changed:

\```yaml
--8<-- "filename.yml"
\```

(had to add the escape characters to display it kind of correctly, lol).

ALizarazoTellez commented 9 months ago

GitHub blocks highlights are escaped too: https://github.com/orgs/community/discussions/16925

Changes:

> [!NOTE]
> Test

With:

> \[!NOTE\] Test

And changes:

> **Note**
> This is a note

With:

> **Note** This is a note
PythonFZ commented 6 months ago

Any updates on this?

mmcdermott commented 1 month ago

It would be really nice to have support for turning off this escape option. Is there any progress on this? I've also added an issue on snippets to support this via a plugin, but it'd be great to have more control in mdformat directly.