diff --git a/_test/extra.txt b/_test/extra.txt index 4f9499c..7c95ca4 100644 --- a/_test/extra.txt +++ b/_test/extra.txt @@ -159,3 +159,79 @@ bbb > &

//= = = = = = = = = = = = = = = = = = = = = = = =// + + +13: fenced code block starting with tab inside list +//- - - - - - - - -// +* foo + ```Makefile + foo + foo + ``` +//- - - - - - - - -// + +//= = = = = = = = = = = = = = = = = = = = = = = =// + +14: fenced code block inside list, mismatched tab start +//- - - - - - - - -// +* foo + ```Makefile + foo + foo + ``` +//- - - - - - - - -// + +//= = = = = = = = = = = = = = = = = = = = = = = =// + + +15: fenced code block inside nested list +//- - - - - - - - -// +* foo + - bar + ```Makefile + foo + foo + ``` +//- - - - - - - - -// + +//= = = = = = = = = = = = = = = = = = = = = = = =// + +16: indented code block starting with a tab. +//- - - - - - - - -// +* foo + + foo + foo + +//- - - - - - - - -// + +//= = = = = = = = = = = = = = = = = = = = = = = =// diff --git a/parser/code_block.go b/parser/code_block.go index d02c21f..8781bb0 100644 --- a/parser/code_block.go +++ b/parser/code_block.go @@ -49,6 +49,19 @@ func (b *codeBlockParser) Continue(node ast.Node, reader text.Reader, pc Context } reader.AdvanceAndSetPadding(pos, padding) _, segment = reader.PeekLine() + + // if code block line starts with a tab, keep a tab as it is. + if segment.Padding != 0 { + offsetWithPadding := reader.LineOffset() + sl, ss := reader.Position() + reader.SetPosition(sl, text.NewSegment(ss.Start-1, ss.Stop)) + if offsetWithPadding == reader.LineOffset() { + segment.Padding = 0 + segment.Start-- + } + reader.SetPosition(sl, ss) + } + node.Lines().Append(segment) reader.Advance(segment.Len() - 1) return Continue | NoChildren diff --git a/parser/fcode_block.go b/parser/fcode_block.go index f5b83ee..75410d7 100644 --- a/parser/fcode_block.go +++ b/parser/fcode_block.go @@ -71,6 +71,17 @@ func (b *fencedCodeBlockParser) Open(parent ast.Node, reader text.Reader, pc Con func (b *fencedCodeBlockParser) Continue(node ast.Node, reader text.Reader, pc Context) State { 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 { + offsetWithPadding := reader.LineOffset() + sl, ss := reader.Position() + reader.SetPosition(sl, text.NewSegment(ss.Start-1, ss.Stop)) + if offsetWithPadding == reader.LineOffset() { + segment.Padding = 0 + segment.Start-- + } + reader.SetPosition(sl, ss) + } w, pos := util.IndentWidth(line, reader.LineOffset()) if w < 4 { i := pos