Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 35 additions & 37 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
return 0, ""
if i >= len(data) {
if i == len(data) {
return i, marker
}
return 0, ""
}

infoStart := i
infoStart := i

if data[i] == '{' {
i++
infoStart++
if data[i] == '{' {
i++
infoStart++

for i < len(data) && data[i] != '}' && data[i] != '\n' {
infoLength++
i++
}
for i < len(data) && data[i] != '}' && data[i] != '\n' {
infoLength++
i++
}

if i >= len(data) || data[i] != '}' {
return 0, ""
}
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--
}
// 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--
}
for infoLength > 0 && isspace(data[infoStart+infoLength-1]) {
infoLength--
}
i++
i = skipChar(data, i, ' ')
} else {
for i < len(data) && !isverticalspace(data[i]) {
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]))
}

Expand Down
4 changes: 2 additions & 2 deletions block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions ref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions testdata/Nested blocks.html
Original file line number Diff line number Diff line change
@@ -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>
9 changes: 9 additions & 0 deletions testdata/Nested blocks.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1. a thing

```build {.line-numbers}
code_fenced_code(line_numbers=true)
```

again

2. Another