Skip to content

I find a code block in the list can not contain more than one blank lines. #849

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

Closed
zjffun opened this issue Jan 31, 2017 · 12 comments
Closed

Comments

@zjffun
Copy link

zjffun commented Jan 31, 2017

I find a code block in the list can not contain more than one blank lines.
(list下面的代码块有两个以上换行会解析错误)

Solution(解决方法)

Let the list matching to the end of the [\s\S]?```,and plus the (?![\s\S]*?```) in the regular expression.
(让列表匹配到[\s\S]
?```结束,正则表达式中加上(?![\s\S]*?```)
Change marked.js->line22 To list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )(?![\s\S]*?```)\n*|\s*$)/,
(将marked.js的22行换成:list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )(?![\s\S]*?```)\n*|\s*$)/,)


like this(please remove '\')(例如这样会解析错):

- testlist
\```
var rendererMD = new marked.Renderer();
//There are two blank lines.(下面有两个空行)


marked.setOptions({
	renderer: rendererMD,
	gfm: true,
	tables: true,
	breaks: false,
	pedantic: false,
	sanitize: false,
	smartLists: true,
	smartypants: false
});
\```

I checked block.gfm and block.list but it beyond my ability to found the wrong.
PS: I am a Chinese boy is not good at English and javascript.Please don't keep in mind if I say something wrong.

@zjffun
Copy link
Author

zjffun commented Jan 31, 2017

test code:

<!doctype html>
<title>marked tests</title>
<p>testing...</p>
<script src="marked.js"></script>
<script>
var str = "- test\n```\ncode\n\n```";
console.log(marked(str));
</script>

ouput:

<ul>
<li>test
\```
code</li>
</ul>
<p>\```</p>

@zjffun
Copy link
Author

zjffun commented Feb 2, 2017

In the 284 line code be truncated by '\n',but the regular is too difficult.

// 283    // list
// 284    if (cap = this.rules.list.exec(src)) {

//src:- test\n```\ncode\n\n```
//cap:array(
//  "- test```code", 
//  "",
//  "-",
//  undefined,
//  undefined,
//  undefined,
//  index : 0,
//  input : "- test```code```"
//)
//this.rules.list:/^( *)((?:[*+-]|\d+\.)) [\s\S]+?(?:\n+(?=\1?(?:[-*_] *){3,}(?:\n+|$))|\n+(?= *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$))|\n{2,}(?! )(?!\1(?:[*+-]|\d+\.) )\n*|\s*$)/

@Jiang-Xuan
Copy link

Jiang-Xuan commented Feb 4, 2017

你为什么要把代码区块写成```\nvar renderer = new Renderer\n```
``这样的语法是用来写内联的代码块的,如果你想要书写大段的代码块,应该用缩进来处理

@zjffun
Copy link
Author

zjffun commented Feb 4, 2017

@Jiang-Xuan 测试的时候字符串里没法打回车。
单行代码:```testcode```

多行代码:
```
testcode
testcode2
```

我遇到的是列表下面的多行代码有回车会被截断:
- lsit1
```
testcode1

```
- lsit2
```
testcode2
```

这种情况- lsit2被标记成了代码,我是想让testcode1,testcode2成为代码

@Jiang-Xuan
Copy link

@1010543618
你是想让代码成为列表里面的内容是吧,这样的情况你需要这样写
- list\n\n\t\tvar helloWiorld = 'hello world'
也就是在列表项后面敲两个回车,然后加上两个tab键,然后在键入你所想要在列表项里面显示的代码

@Jiang-Xuan
Copy link

@1010543618
也许是我理解有误,不过你的表述应该再清晰点
如果你想要单独的一个代码块,使用一个tab键来缩进你的代码,最好在你的代码区域上下都放置一个空白行,就是只有空格或者是连空格都没有的行。
单独的三个反引号不是用来包裹代码的,是用来当你需要渲染代码的样式的时候用的

@zjffun
Copy link
Author

zjffun commented Feb 4, 2017

@Jiang-Xuan 我是这几天才看的markdown,以前一直没接触过,感觉每种解析器的解析都有点差别。我是准备想办法让```包裹的代码块里的换行不被列表的-识别了当成结束列表,但js没学好=_=。我再试试不然就像你说的先结束了列表在用代码块。十分感谢^_^

@Jiang-Xuan
Copy link

@1010543618 解析器都有自己的语法,想要自己有一种语法,只能去重写全部源代码或者一部分,我就在重写这个包来让它更符合我的博客站点,所以才看到你的问题=_=。同样是菜鸟

@zjffun
Copy link
Author

zjffun commented Feb 4, 2017

@Jiang-Xuan 恩,造个轮子可有点难。反正假期有空好好研究研究作者的代码

@fadiquader
Copy link

fadiquader commented Feb 11, 2017

use
` $('.content-markdown').each(function () {
var content = $(this).text();
content = content.trim()
var markedContent = marked(content);

    $(this).html(markedContent);
});`

@zjffun
Copy link
Author

zjffun commented Feb 12, 2017

@fadiquader
eh... I just tried this method,but it can only remove white space characters or other predefined character on either side of the string.
I want to remove line feed character in a one string.
Maybe I should use regular expression to match \n\n and remove one \n.
Thank you.

@zjffun zjffun changed the title I find a code block in the list can not contain blank lines. I find a code block in the list can not contain more than one blank lines. Mar 3, 2017
@joshbruce
Copy link
Member

#983

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

4 participants