diff options
Diffstat (limited to 'vendor/github.com/gomarkdown/markdown')
-rw-r--r-- | vendor/github.com/gomarkdown/markdown/parser/block.go | 90 | ||||
-rw-r--r-- | vendor/github.com/gomarkdown/markdown/parser/inline.go | 47 |
2 files changed, 91 insertions, 46 deletions
diff --git a/vendor/github.com/gomarkdown/markdown/parser/block.go b/vendor/github.com/gomarkdown/markdown/parser/block.go index 2b48d52d..dee173f8 100644 --- a/vendor/github.com/gomarkdown/markdown/parser/block.go +++ b/vendor/github.com/gomarkdown/markdown/parser/block.go @@ -858,12 +858,9 @@ func isFenceLine(data []byte, syntax *string, oldmarker string) (end int, marker return 0, "" } - // TODO(shurcooL): It's probably a good idea to simplify the 2 code paths here - // into one, always get the syntax, and discard it if the caller doesn't care. - if syntax != nil { - syn := 0 + // if just read the beginning marker, read the syntax + if oldmarker == "" { i = skipChar(data, i, ' ') - if i >= n { if i == n { return i, marker @@ -871,41 +868,15 @@ func isFenceLine(data []byte, syntax *string, oldmarker string) (end int, marker return 0, "" } - syntaxStart := i - - if data[i] == '{' { - i++ - syntaxStart++ - - for i < n && data[i] != '}' && data[i] != '\n' { - syn++ - i++ - } - - if i >= n || data[i] != '}' { - return 0, "" - } - - // strip all whitespace at the beginning and the end - // of the {} block - for syn > 0 && isSpace(data[syntaxStart]) { - syntaxStart++ - syn-- - } - - for syn > 0 && isSpace(data[syntaxStart+syn-1]) { - syn-- - } - - i++ - } else { - for i < n && !isSpace(data[i]) { - syn++ - i++ - } + syntaxStart, syntaxLen := syntaxRange(data, &i) + if syntaxStart == 0 && syntaxLen == 0 { + return 0, "" } - *syntax = string(data[syntaxStart : syntaxStart+syn]) + // caller wants the syntax + if syntax != nil { + *syntax = string(data[syntaxStart : syntaxStart+syntaxLen]) + } } i = skipChar(data, i, ' ') @@ -918,6 +889,47 @@ func isFenceLine(data []byte, syntax *string, oldmarker string) (end int, marker return i + 1, marker // Take newline into account. } +func syntaxRange(data []byte, iout *int) (int, int) { + n := len(data) + syn := 0 + i := *iout + syntaxStart := i + if data[i] == '{' { + i++ + syntaxStart++ + + for i < n && data[i] != '}' && data[i] != '\n' { + syn++ + i++ + } + + if i >= n || data[i] != '}' { + return 0, 0 + } + + // strip all whitespace at the beginning and the end + // of the {} block + for syn > 0 && isSpace(data[syntaxStart]) { + syntaxStart++ + syn-- + } + + for syn > 0 && isSpace(data[syntaxStart+syn-1]) { + syn-- + } + + i++ + } else { + for i < n && !isSpace(data[i]) { + syn++ + i++ + } + } + + *iout = i + return syntaxStart, syn +} + // fencedCodeBlock returns the end index if data contains a fenced code block at the beginning, // or 0 otherwise. It writes to out if doRender is true, otherwise it has no side effects. // If doRender is true, a final newline is mandatory to recognize the fenced code block. @@ -1416,7 +1428,7 @@ gatherlines: // we need to add leadingWhiteSpaces + 1 spaces in the beginning of the chunk if indentIndex >= 4 && p.dliPrefix(chunk) <= 0 { leadingWhiteSpaces := skipChar(chunk, 0, ' ') - chunk = data[ line+indentIndex - (leadingWhiteSpaces + 1) : i] + chunk = data[line+indentIndex-(leadingWhiteSpaces+1) : i] } // to be a nested list, it must be indented more diff --git a/vendor/github.com/gomarkdown/markdown/parser/inline.go b/vendor/github.com/gomarkdown/markdown/parser/inline.go index d68983f7..1f23935c 100644 --- a/vendor/github.com/gomarkdown/markdown/parser/inline.go +++ b/vendor/github.com/gomarkdown/markdown/parser/inline.go @@ -131,7 +131,11 @@ func codeSpan(p *Parser, data []byte, offset int) (int, ast.Node) { // find the next delimiter i, end := 0, 0 + hasLFBeforeDelimiter := false for end = nb; end < len(data) && i < nb; end++ { + if data[end] == '\n' { + hasLFBeforeDelimiter = true + } if data[end] == '`' { i++ } else { @@ -144,6 +148,18 @@ func codeSpan(p *Parser, data []byte, offset int) (int, ast.Node) { return 0, nil } + // If there are non-space chars after the ending delimiter and before a '\n', + // flag that this is not a well formed fenced code block. + hasCharsAfterDelimiter := false + for j := end; j < len(data); j++ { + if data[j] == '\n' { + break + } + if !isSpace(data[j]) { + hasCharsAfterDelimiter = true + } + } + // trim outside whitespace fBegin := nb for fBegin < end && data[fBegin] == ' ' { @@ -155,14 +171,31 @@ func codeSpan(p *Parser, data []byte, offset int) (int, ast.Node) { fEnd-- } - // render the code span - if fBegin != fEnd { - code := &ast.Code{} - code.Literal = data[fBegin:fEnd] - return end, code + if fBegin == fEnd { + return end, nil } - return end, nil + // if delimiter has 3 backticks + if nb == 3 { + i := fBegin + syntaxStart, syntaxLen := syntaxRange(data, &i) + + // If we found a '\n' before the end marker and there are only spaces + // after the end marker, then this is a code block. + if hasLFBeforeDelimiter && !hasCharsAfterDelimiter { + codeblock := &ast.CodeBlock{ + IsFenced: true, + Info: data[syntaxStart : syntaxStart+syntaxLen], + } + codeblock.Literal = data[i:fEnd] + return end, codeblock + } + } + + // render the code span + code := &ast.Code{} + code.Literal = data[fBegin:fEnd] + return end, code } // newline preceded by two spaces becomes <br> @@ -781,7 +814,7 @@ func entity(p *Parser, data []byte, offset int) (int, ast.Node) { codepoint, err = strconv.ParseUint(string(ent[2:len(ent)-1]), 10, 64) } if err == nil { // only if conversion was valid return here. - return end, newTextNode([]byte(string(codepoint))) + return end, newTextNode([]byte(string(rune(codepoint)))) } return end, newTextNode(ent) |