diff --git a/parser/fcode_block.go b/parser/fcode_block.go index 8d36ffe..a837d2b 100644 --- a/parser/fcode_block.go +++ b/parser/fcode_block.go @@ -47,12 +47,14 @@ func (b *fencedCodeBlockParser) Open(parent ast.Node, reader text.Reader, pc Con rest := line[i:] left := util.TrimLeftSpaceLength(rest) right := util.TrimRightSpaceLength(rest) - infoStart, infoStop := segment.Start+i+left, segment.Stop-right - value := rest[left : len(rest)-right] - if fenceChar == '`' && bytes.IndexByte(value, '`') > -1 { - return nil, NoChildren - } else if infoStart != infoStop { - info = ast.NewTextSegment(text.NewSegment(infoStart, infoStop)) + if left < len(rest)-right { + infoStart, infoStop := segment.Start+i+left, segment.Stop-right + value := rest[left : len(rest)-right] + if fenceChar == '`' && bytes.IndexByte(value, '`') > -1 { + return nil, NoChildren + } else if infoStart != infoStop { + info = ast.NewTextSegment(text.NewSegment(infoStart, infoStop)) + } } } pc.Set(fencedCodeBlockInfoKey, &fenceData{fenceChar, findent, oFenceLength}) diff --git a/util/util.go b/util/util.go index 7664d6f..c2bac4a 100644 --- a/util/util.go +++ b/util/util.go @@ -117,6 +117,7 @@ func VisualizeSpaces(bs []byte) []byte { bs = bytes.Replace(bs, []byte(" "), []byte("[SPACE]"), -1) bs = bytes.Replace(bs, []byte("\t"), []byte("[TAB]"), -1) bs = bytes.Replace(bs, []byte("\n"), []byte("[NEWLINE]\n"), -1) + bs = bytes.Replace(bs, []byte("\r"), []byte("[CR]\n"), -1) return bs }