Skip to content

Commit

Permalink
Fix #229
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin committed Jun 27, 2021
1 parent 040b478 commit 759cc35
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
42 changes: 42 additions & 0 deletions _test/extra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,45 @@ foo
</li>
</ul>
//= = = = = = = = = = = = = = = = = = = = = = = =//

21: Fenced code block within list can start with tab
//- - - - - - - - -//
- List

```
A
B
C
```
//- - - - - - - - -//
<ul>
<li>
<p>List</p>
<pre><code>A
B
C
</code></pre>
</li>
</ul>
//= = = = = = = = = = = = = = = = = = = = = = = =//
22: Indented code block within list can start with tab
//- - - - - - - - -//
- List

A
B
C

a
//- - - - - - - - -//
<ul>
<li>
<p>List</p>
<pre><code>A
B
C
</code></pre>
</li>
</ul>
<p>a</p>
//= = = = = = = = = = = = = = = = = = = = = = = =//
8 changes: 4 additions & 4 deletions parser/fcode_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion parser/list_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 759cc35

Please sign in to comment.