mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
fix(lists): codeblocks inside lists are now correctly parsed
Closes #494
This commit is contained in:
parent
5e0ed809db
commit
8cecdf0382
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -87,14 +87,14 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
|
|||
return '¨A' + wm2;
|
||||
});
|
||||
|
||||
// SPECIAL CASE: an heading followed by a paragraph of text that is not separated by a double newline
|
||||
// SPECIAL CASE: a heading followed by a paragraph of text that is not separated by a double newline
|
||||
// or/nor indented. ex:
|
||||
//
|
||||
// - # foo
|
||||
// bar is great
|
||||
//
|
||||
// While this does now follow the spec per se, not allowing for this might cause confusion since
|
||||
// header blocks don't need double newlines after
|
||||
// header blocks don't need double-newlines after
|
||||
if (/^#+.+\n.+/.test(item)) {
|
||||
item = item.replace(/^(#+.+)$/m, '$1\n');
|
||||
}
|
||||
|
@ -103,7 +103,47 @@ showdown.subParser('makehtml.lists', function (text, options, globals) {
|
|||
// Has a double return (multi paragraph)
|
||||
if (m1 || (item.search(/\n{2,}/) > -1)) {
|
||||
item = showdown.subParser('makehtml.githubCodeBlocks')(item, options, globals);
|
||||
item = showdown.subParser('makehtml.blockGamut')(item, options, globals);
|
||||
item = showdown.subParser('makehtml.blockQuotes')(item, options, globals);
|
||||
item = showdown.subParser('makehtml.headers')(item, options, globals);
|
||||
item = showdown.subParser('makehtml.lists')(item, options, globals);
|
||||
item = showdown.subParser('makehtml.codeBlocks')(item, options, globals);
|
||||
item = showdown.subParser('makehtml.tables')(item, options, globals);
|
||||
item = showdown.subParser('makehtml.hashHTMLBlocks')(item, options, globals);
|
||||
//item = showdown.subParser('makehtml.paragraphs')(item, options, globals);
|
||||
|
||||
// TODO: This is a copy of the paragraph parser
|
||||
// This is a provisory fix for issue #494
|
||||
// For a permanente fix we need to rewrite the paragraph parser, passing the unhashify logic outside
|
||||
// so that we can call the paragraph parser without accidently unashifying previously parsed blocks
|
||||
|
||||
// Strip leading and trailing lines:
|
||||
item = item.replace(/^\n+/g, '');
|
||||
item = item.replace(/\n+$/g, '');
|
||||
|
||||
var grafs = item.split(/\n{2,}/g),
|
||||
grafsOut = [],
|
||||
end = grafs.length; // Wrap <p> tags
|
||||
|
||||
for (var i = 0; i < end; i++) {
|
||||
var str = grafs[i];
|
||||
// if this is an HTML marker, copy it
|
||||
if (str.search(/¨([KG])(\d+)\1/g) >= 0) {
|
||||
grafsOut.push(str);
|
||||
|
||||
// test for presence of characters to prevent empty lines being parsed
|
||||
// as paragraphs (resulting in undesired extra empty paragraphs)
|
||||
} else if (str.search(/\S/) >= 0) {
|
||||
str = showdown.subParser('makehtml.spanGamut')(str, options, globals);
|
||||
str = str.replace(/^([ \t]*)/g, '<p>');
|
||||
str += '</p>';
|
||||
grafsOut.push(str);
|
||||
}
|
||||
}
|
||||
item = grafsOut.join('\n');
|
||||
// Strip leading and trailing lines:
|
||||
item = item.replace(/^\n+/g, '');
|
||||
item = item.replace(/\n+$/g, '');
|
||||
|
||||
} else {
|
||||
|
||||
// Recursion for sub-lists:
|
||||
|
|
|
@ -264,14 +264,17 @@ This is a second.
|
|||
</code></pre></li>
|
||||
<li><p>Blue</p></li>
|
||||
<li><p>Red</p>
|
||||
<pre><code>* Green<pre><code>Try this code:
|
||||
<pre><code>* Green
|
||||
|
||||
This is an embedded code block.
|
||||
Try this code:
|
||||
|
||||
Then this:
|
||||
This is an embedded code block.
|
||||
|
||||
More code!
|
||||
</code></pre>* Blue
|
||||
Then this:
|
||||
|
||||
More code!
|
||||
|
||||
* Blue
|
||||
* Red
|
||||
</code></pre></li>
|
||||
</ul>
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<pre><code>public static void main(String[] args) {
|
||||
|
||||
for (int i = 0; i < 10 && true; i++) {
|
||||
|
||||
System.out.println("Hello World");
|
||||
}
|
||||
|
||||
// stuff here is affected as well <>&&%
|
||||
}
|
||||
</code></pre>
|
|
@ -0,0 +1,11 @@
|
|||
```
|
||||
public static void main(String[] args) {
|
||||
|
||||
for (int i = 0; i < 10 && true; i++) {
|
||||
|
||||
System.out.println("Hello World");
|
||||
}
|
||||
|
||||
// stuff here is affected as well <>&&%
|
||||
}
|
||||
```
|
|
@ -0,0 +1,13 @@
|
|||
<ol>
|
||||
<li><p>Code block as part of list</p>
|
||||
<pre><code>public static void main(String[] args) {
|
||||
|
||||
for (int i = 0; i < 10 && true; i++) {
|
||||
|
||||
System.out.println("Hello World");
|
||||
}
|
||||
|
||||
// stuff here is affected as well <>&&%
|
||||
}
|
||||
</code></pre></li>
|
||||
</ol>
|
|
@ -0,0 +1,13 @@
|
|||
1. Code block as part of list
|
||||
|
||||
```
|
||||
public static void main(String[] args) {
|
||||
|
||||
for (int i = 0; i < 10 && true; i++) {
|
||||
|
||||
System.out.println("Hello World");
|
||||
}
|
||||
|
||||
// stuff here is affected as well <>&&%
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue
Block a user