Fix code fence handling. Parse info line after code fences even if the user doesn't ask for it, and keep it only if they want it.
parent
d3b5b032dc
commit
5e3fe3c85b
78
block.go
78
block.go
|
@ -605,53 +605,51 @@ func isFenceLine(data []byte, info *string, oldmarker string) (end int, marker s
|
|||
return 0, ""
|
||||
}
|
||||
|
||||
// TODO(shurcooL): It's probably a good idea to simplify the 2 code paths here
|
||||
// into one, always get the info string, and discard it if the caller doesn't care.
|
||||
if info != nil {
|
||||
infoLength := 0
|
||||
i = skipChar(data, i, ' ')
|
||||
// Look for info on the code block.
|
||||
infoLength := 0
|
||||
i = skipChar(data, i, ' ')
|
||||
|
||||
if i >= len(data) {
|
||||
if i == len(data) {
|
||||
return i, marker
|
||||
}
|
||||
if i >= len(data) {
|
||||
if i == len(data) {
|
||||
return i, marker
|
||||
}
|
||||
return 0, ""
|
||||
}
|
||||
|
||||
infoStart := i
|
||||
|
||||
if data[i] == '{' {
|
||||
i++
|
||||
infoStart++
|
||||
|
||||
for i < len(data) && data[i] != '}' && data[i] != '\n' {
|
||||
infoLength++
|
||||
i++
|
||||
}
|
||||
|
||||
if i >= len(data) || data[i] != '}' {
|
||||
return 0, ""
|
||||
}
|
||||
|
||||
infoStart := i
|
||||
|
||||
if data[i] == '{' {
|
||||
i++
|
||||
// strip all whitespace at the beginning and the end
|
||||
// of the {} block
|
||||
for infoLength > 0 && isspace(data[infoStart]) {
|
||||
infoStart++
|
||||
|
||||
for i < len(data) && data[i] != '}' && data[i] != '\n' {
|
||||
infoLength++
|
||||
i++
|
||||
}
|
||||
|
||||
if i >= len(data) || data[i] != '}' {
|
||||
return 0, ""
|
||||
}
|
||||
|
||||
// strip all whitespace at the beginning and the end
|
||||
// of the {} block
|
||||
for infoLength > 0 && isspace(data[infoStart]) {
|
||||
infoStart++
|
||||
infoLength--
|
||||
}
|
||||
|
||||
for infoLength > 0 && isspace(data[infoStart+infoLength-1]) {
|
||||
infoLength--
|
||||
}
|
||||
i++
|
||||
i = skipChar(data, i, ' ')
|
||||
} else {
|
||||
for i < len(data) && !isverticalspace(data[i]) {
|
||||
infoLength++
|
||||
i++
|
||||
}
|
||||
infoLength--
|
||||
}
|
||||
|
||||
for infoLength > 0 && isspace(data[infoStart+infoLength-1]) {
|
||||
infoLength--
|
||||
}
|
||||
i++
|
||||
i = skipChar(data, i, ' ')
|
||||
} else {
|
||||
for i < len(data) && !isverticalspace(data[i]) {
|
||||
infoLength++
|
||||
i++
|
||||
}
|
||||
}
|
||||
if info != nil {
|
||||
*info = strings.TrimSpace(string(data[infoStart : infoStart+infoLength]))
|
||||
}
|
||||
|
||||
|
|
|
@ -1092,7 +1092,7 @@ func TestFencedCodeBlock(t *testing.T) {
|
|||
"<p>``` lisp\nno ending</p>\n",
|
||||
|
||||
"~~~ lisp\nend with language\n~~~ lisp\n",
|
||||
"<p>~~~ lisp\nend with language\n~~~ lisp</p>\n",
|
||||
"<pre><code class=\"language-lisp\">end with language\n</code></pre>\n",
|
||||
|
||||
"```\nmismatched begin and end\n~~~\n",
|
||||
"<p>```\nmismatched begin and end\n~~~</p>\n",
|
||||
|
@ -1558,7 +1558,7 @@ func TestFencedCodeBlock_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
|
|||
"<p>``` lisp\nno ending</p>\n",
|
||||
|
||||
"~~~ lisp\nend with language\n~~~ lisp\n",
|
||||
"<p>~~~ lisp\nend with language\n~~~ lisp</p>\n",
|
||||
"<pre><code class=\"language-lisp\">end with language\n</code></pre>\n",
|
||||
|
||||
"```\nmismatched begin and end\n~~~\n",
|
||||
"<p>```\nmismatched begin and end\n~~~</p>\n",
|
||||
|
|
|
@ -40,6 +40,7 @@ func TestReference(t *testing.T) {
|
|||
"Markdown Documentation - Basics",
|
||||
"Markdown Documentation - Syntax",
|
||||
"Nested blockquotes",
|
||||
"Nested blocks",
|
||||
"Ordered and unordered lists",
|
||||
"Strong and em together",
|
||||
"Tabs",
|
||||
|
@ -69,6 +70,7 @@ func TestReference_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
|
|||
"Markdown Documentation - Basics",
|
||||
"Markdown Documentation - Syntax",
|
||||
"Nested blockquotes",
|
||||
"Nested blocks",
|
||||
"Ordered and unordered lists",
|
||||
"Strong and em together",
|
||||
"Tabs",
|
||||
|
@ -102,6 +104,7 @@ func BenchmarkReference(b *testing.B) {
|
|||
"Markdown Documentation - Basics",
|
||||
"Markdown Documentation - Syntax",
|
||||
"Nested blockquotes",
|
||||
"Nested blocks",
|
||||
"Ordered and unordered lists",
|
||||
"Strong and em together",
|
||||
"Tabs",
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<ol>
|
||||
<li><p>a thing</p>
|
||||
|
||||
<p><code>build {.line-numbers}
|
||||
code_fenced_code(line_numbers=true)
|
||||
</code></p>
|
||||
|
||||
<p>again</p></li>
|
||||
|
||||
<li><p>Another</p></li>
|
||||
</ol>
|
|
@ -0,0 +1,9 @@
|
|||
1. a thing
|
||||
|
||||
```build {.line-numbers}
|
||||
code_fenced_code(line_numbers=true)
|
||||
```
|
||||
|
||||
again
|
||||
|
||||
2. Another
|
Loading…
Reference in New Issue