mdformat icon indicating copy to clipboard operation
mdformat copied to clipboard

mdformat breaks Hugo shortcodes by escaping `<`

Open jamesbraza opened this issue 1 year ago • 8 comments

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

jamesbraza avatar Jun 19 '23 23:06 jamesbraza

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:

welcome[bot] avatar Jun 19 '23 23:06 welcome[bot]

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.

Oliver-Habersetzer avatar Oct 11 '23 20:10 Oliver-Habersetzer

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).

BartKeulen avatar Nov 24 '23 10:11 BartKeulen

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

ALizarazoTellez avatar Nov 27 '23 02:11 ALizarazoTellez

Any updates on this?

PythonFZ avatar Feb 14 '24 19:02 PythonFZ

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.

mmcdermott avatar Aug 08 '24 18:08 mmcdermott