markdown: attr_list breaks if the value contains braces, requires HTML-encoding them

This issue originated from squidfunk/mkdocs-material#6177 where I was exploring the “override copied text” feature.

The following code block breaks Markdown parsing:

``` { .c data-copy="int main() { return 0; }" }
Try copying me for some C code
```

It doesn’t quite make sense to me as everything is already inside double quotes.

Instead, HTML-encoding the braces (and you can add newlines) solves the problem:

``` { .c data-copy="int main() {
  return 0;
&#125" }
Try copying me for some C code
```

Using HTML-encoding is not intuitive to most users. Maybe this could get changed to Python escapes?

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Reactions: 1
  • Comments: 16 (6 by maintainers)

Most upvoted comments

Well, regardless, the next version of pymdown-extensions will handle braces better in code block attributes.

@squidfunk thanks for the explanation. I commented on your issue with a suggestion for a different way to solve your problem. Whether you go that route or another is your choice. But the best you can hope for from us here is to allow curly braces in values. All other limitations will remain.

@facelessuser the one question I was hoping you would answer you didn’t. The attr_list parser is not the issue, The issue is that fenced_code doesn’t pass the curly braces on to attr_list. I was wondering if maybe superfences wasn’t so restrictive.