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

Lists with code fences work incorrectly if code contains "[" symbol #712

Closed
evil-shrike opened this issue Jan 25, 2016 · 4 comments
Closed

Comments

@evil-shrike
Copy link

input.md:

1. see code:  
\```
__newValues?: {
    [key: string]: any;
}
\```
2. next item

In token method "list" rule captures list items:

    // list
    if (cap = this.rules.list.exec(src)) {
      src = src.substring(cap[0].length);

here src will be:

 [key: string]: any;
}
\```

I added "" before block fence.

@Feder1co5oave
Copy link
Contributor

Why did you add the backslashes? What is the output you expect from that source?

@evil-shrike
Copy link
Author

@Feder1co5oave I added backslashes to prevent parsing this markdown here (by github). Actual source input.md has no "".

@Feder1co5oave
Copy link
Contributor

Ouch, you're right. This does look nasty!
I believe the problem is that [key: string]: any; is interpreted as a "definition" (a link reference that you usually put at the end of the document, but is expected to be found also inside other elements like lists and blockquotes).
Moreover, the output changes whenever the indentation of that code block is changed (I'm used to indent the content of a list item). I was able to get the correct output by applying the following patch:

diff --git a/lib/marked.js b/lib/marked.js
index 0711b00..d4e34e9 100644
--- a/lib/marked.js
+++ b/lib/marked.js
@@ -19,7 +19,7 @@ var block = {
   nptable: noop,
   lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
   blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
-  list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
+  list: /^( *)(bull) [\s\S]+?(?:hr|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
   html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
   def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
   table: noop,

However that lists regex definitely needs to be reviewed.

You can also easily work around this by putting a space between the ] and the :

@joshbruce
Copy link
Member

#982

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

3 participants