diff --git a/_test/extra.txt b/_test/extra.txt index 7b3ec0c..d0b7555 100644 --- a/_test/extra.txt +++ b/_test/extra.txt @@ -323,3 +323,45 @@ foo //= = = = = = = = = = = = = = = = = = = = = = = =// + +21: Fenced code block within list can start with tab +//- - - - - - - - -// +- List + + ``` + A + B + C + ``` +//- - - - - - - - -// + +//= = = = = = = = = = = = = = = = = = = = = = = =// +22: Indented code block within list can start with tab +//- - - - - - - - -// +- List + + A + B + C + +a +//- - - - - - - - -// + +

a

+//= = = = = = = = = = = = = = = = = = = = = = = =// diff --git a/parser/fcode_block.go b/parser/fcode_block.go index 63c2fd4..2bb688f 100644 --- a/parser/fcode_block.go +++ b/parser/fcode_block.go @@ -72,10 +72,6 @@ func (b *fencedCodeBlockParser) Continue(node ast.Node, reader text.Reader, pc C line, segment := reader.PeekLine() fdata := pc.Get(fencedCodeBlockInfoKey).(*fenceData) - // if code block line starts with a tab, keep a tab as it is. - if segment.Padding != 0 { - preserveLeadingTabInCodeBlock(&segment, reader, fdata.indent) - } w, pos := util.IndentWidth(line, reader.LineOffset()) if w < 4 { i := pos @@ -94,6 +90,10 @@ func (b *fencedCodeBlockParser) Continue(node ast.Node, reader text.Reader, pc C pos, padding := util.DedentPositionPadding(line, reader.LineOffset(), segment.Padding, fdata.indent) seg := text.NewSegmentPadding(segment.Start+pos, segment.Stop, padding) + // if code block line starts with a tab, keep a tab as it is. + if padding != 0 { + preserveLeadingTabInCodeBlock(&seg, reader, fdata.indent) + } node.Lines().Append(seg) reader.AdvanceAndSetPadding(segment.Stop-segment.Start-pos-1, padding) return Continue | NoChildren diff --git a/parser/list_item.go b/parser/list_item.go index 6c8db95..e29b0a4 100644 --- a/parser/list_item.go +++ b/parser/list_item.go @@ -53,7 +53,7 @@ func (b *listItemParser) Open(parent ast.Node, reader text.Reader, pc Context) ( func (b *listItemParser) Continue(node ast.Node, reader text.Reader, pc Context) State { line, _ := reader.PeekLine() if util.IsBlank(line) { - reader.Advance(len(line)-1) + reader.Advance(len(line) - 1) return Continue | HasChildren } diff --git a/testutil/testutil.go b/testutil/testutil.go index 5c0a1e6..4df5993 100644 --- a/testutil/testutil.go +++ b/testutil/testutil.go @@ -277,7 +277,11 @@ func DiffPretty(v1, v2 []byte) []byte { c = " " } for _, line := range diff.Lines { - b.WriteString(fmt.Sprintf("%s | %s\n", c, line)) + if c != " " { + b.WriteString(fmt.Sprintf("%s | %s\n", c, util.VisualizeSpaces(line))) + } else { + b.WriteString(fmt.Sprintf("%s | %s\n", c, line)) + } } } return b.Bytes()