remarkjs / remark-directive

remark plugin to support directives
https://remark.js.org
MIT License
269 stars 17 forks source link

Escaping quotes does not work #14

Closed 2manyvcos closed 1 year ago

2manyvcos commented 1 year ago

Initial checklist

Affected packages and versions

remark-directive

Link to runnable example

No response

Steps to reproduce

It is not possible to escape quotes in attribute, e.g. the following two examples do not work:

:test[content]{a="content with escaped \" quote"}
:test[content]{a='content with escaped \' quote'}

The only way to do this currently is to use ASCII codes:

:test[content]{a="content with escaped " quote"}
:test[content]{a='content with escaped ' quote'}

Expected behavior

Escape sequences should work for quotes.

Actual behavior

The directive is not parsed.

Runtime

No response

Package manager

No response

OS

No response

Build and bundle tools

No response

2manyvcos commented 1 year ago

Here is a reproduction example:

https://codesandbox.io/p/sandbox/flamboyant-mestorf-n33ptd?file=%2Fsrc%2Fapp.tsx%3A17%2C4

wooorm commented 1 year ago

This is intentional. Markdown supports character references in lots of places. It never supports C-style escapes. Therefore, it is logical to support character references and not C-style escapes here, too.

ASCII codes

That’s not what those are. Those are character references, as defined by the CM and HTML specs.

2manyvcos commented 1 year ago

Thank you for the clarification.

Even though I am a bit confused, because there is a section mentioning backslash escapes in the CommonMark spec and it is possible to escape the whole directive by adding a backslash before the colon, like described in https://github.com/remarkjs/remark-directive/issues/5#issuecomment-869131256.

Also, the following is valid Markdown:

[url with \] escape](test)

[url with ] escape](test)

It even is supported in the content of directives:

:test[content with \] escape]{a=test}
wooorm commented 1 year ago

Oh that, sorry, I missed what this was about. I modelled the attributes after how attributes work in HTML. So also unquoted ones work. And more character references work than solely in markdown. This means you can copy/paste things.

2manyvcos commented 1 year ago

Oh, I see now! Thank you, that clarified it.