Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backticks have rights #69

Open
wordbugs opened this issue Apr 24, 2023 · 1 comment
Open

backticks have rights #69

wordbugs opened this issue Apr 24, 2023 · 1 comment

Comments

@wordbugs
Copy link

wordbugs commented Apr 24, 2023

Backticks (`) should be able to exist within codespans (as they do in the base markedjs and in this github issue) as long as the number of backticks used as delimiters is different from the number of backticks in any inner group of backticks.

For this given markdown input:

`codespan`
``codespan with one backtick (`)``
`codespan with many backticks (``````)`

The Codespan should remove only the outer backticks:

codespan
codespan with one backtick (`)
codespan with many backticks (``````)

Instead, all backticks are removed:

<p><code>codespan</code></p>
<p><code>codespan with one backtick ()</code></p>
<p><code>codespan with many backticks ()</code></p>

Using text instead of raw fixes it (I've used a custom renderer to test it).
I've made a proposal with the same name as this issue; it changes renderers/Codespan.svelte like this:

  <script>
-   export let raw
+   export let text
  </script>

- <code>{raw.replace(/`/g, '')}</code>
+ <code>{text}</code>
@wordbugs
Copy link
Author

wordbugs commented Apr 24, 2023

I've now realized raw was there for a reason; characters like " seem to be unescaped into their html codes (&quot;).

Here are two possible solutions:

  1. Use raw.replace(/^`+|`+$/g, ''); to strip backticks from the beginning and end of the string (you don't have to worry about there being different numbers of backticks at each side; the lexer has already taken care of that). I've proposed it here.
  2. Unescape the html codes: new DOMParser().parseFromString(text, "text/html").documentElement.textContent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant