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

grammar for inline codes is not good #1052

Closed
icecola2018 opened this issue Feb 15, 2018 · 4 comments
Closed

grammar for inline codes is not good #1052

icecola2018 opened this issue Feb 15, 2018 · 4 comments
Labels
category: code blocks L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue

Comments

@icecola2018
Copy link

Expectation

``foo

foo``

`foo``

``foo`

should be

<p>foo``</p>
<p>``foo</p>
<p>`foo``</p>
<p>``foo`</p>

Result

marked returns

<p><code></code>foo</p>
<p>foo<code></code></p>
<p><code>foo`</code></p>
<p><code></code>foo`</p>

What was attempted

I edited marked.js:

  1. line 471, replace code: /^(`+)(\s*)([\s\S]*?[^`]?)\2\1(?!`)/ with code: /^(`+(?!`))([\s\S]*?[^`])\1(?!`)/
  2. line 694, replace cap[3] with cap[2]

then get

<p>foo``</p>
<p>``foo</p>
<p>`foo``</p>
<p>`<code>foo</code></p>

However it doesn't work well on the last one.

@Feder1co5oave
Copy link
Contributor

Thanks for reporting, this was partially my mistake in #1013.

Babelmark for reference.

The fix you suggest brings us back before #1013 so it is not right.
I have an easy partial fix for this which would produce the following output:

<p>``foo</p>
<p>foo``</p>
<p>`foo``</p>
<p><code>`foo</code></p>

I'm adding this to the consolidating issue hoping that we'll conform with commonmark on codespans too.

@icecola2018
Copy link
Author

Reply to @Feder1co5oave

I see the problem in #1030 .

Actually my suggestion

/^(`+(?!`))([\s\S]*?[^`])\1(?!`)/

is different from the one before #1030

/^(`+)([\s\S]*?[^`])\1(?!`)/

I found that back references (such as \1) perform strangely when they refer to groups ending with + or *. In fact \1 has chance to match any quantities of `.

For example, if (`+) matched `` and it was not closed, then \1 would match ` or ``` or ```` or ...
That's why /^(`+)([\s\S]*?[^`])\1(?!`)/ works well on `` ` `` but wrong on `` ` ```.


Then I added (?!`) after + to the first group, which seemed no sense. Actually it worked well, \1 will only match the same string that the group matches. You may test it to be sure.


I'm not very good at English, so I will try my best to explain if you don't understand what I want to say.

@joshbruce joshbruce added L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue category: code blocks labels Feb 15, 2018
@Feder1co5oave
Copy link
Contributor

Thanks, you've been very clear and detailed, I'll look into this!

@UziTech
Copy link
Member

UziTech commented Dec 5, 2018

this seems to be fixed in the latest version of marked demo

@UziTech UziTech closed this as completed Dec 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: code blocks L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue
Projects
None yet
Development

No branches or pull requests

4 participants