diff --git a/block.go b/block.go index b8607474..765ca7ff 100644 --- a/block.go +++ b/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 - } - 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])) } diff --git a/block_test.go b/block_test.go index 326c3110..b4db8eba 100644 --- a/block_test.go +++ b/block_test.go @@ -1092,7 +1092,7 @@ func TestFencedCodeBlock(t *testing.T) { "

``` lisp\nno ending

\n", "~~~ lisp\nend with language\n~~~ lisp\n", - "

~~~ lisp\nend with language\n~~~ lisp

\n", + "
end with language\n
\n", "```\nmismatched begin and end\n~~~\n", "

```\nmismatched begin and end\n~~~

\n", @@ -1558,7 +1558,7 @@ func TestFencedCodeBlock_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) { "

``` lisp\nno ending

\n", "~~~ lisp\nend with language\n~~~ lisp\n", - "

~~~ lisp\nend with language\n~~~ lisp

\n", + "
end with language\n
\n", "```\nmismatched begin and end\n~~~\n", "

```\nmismatched begin and end\n~~~

\n", diff --git a/ref_test.go b/ref_test.go index a2e689ca..e7948697 100644 --- a/ref_test.go +++ b/ref_test.go @@ -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", diff --git a/testdata/Nested blocks.html b/testdata/Nested blocks.html new file mode 100644 index 00000000..868d1341 --- /dev/null +++ b/testdata/Nested blocks.html @@ -0,0 +1,11 @@ +
    +
  1. a thing

    + +

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

    + +

    again

  2. + +
  3. Another

  4. +
diff --git a/testdata/Nested blocks.text b/testdata/Nested blocks.text new file mode 100644 index 00000000..bb446185 --- /dev/null +++ b/testdata/Nested blocks.text @@ -0,0 +1,9 @@ +1. a thing + + ```build {.line-numbers} + code_fenced_code(line_numbers=true) + ``` + + again + +2. Another