Skip to content

Commit

Permalink
Fixes #262
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin committed Nov 8, 2021
1 parent 0283c9c commit 907eb99
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
22 changes: 22 additions & 0 deletions _test/extra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,25 @@ b
<p>a <br />
b</p>
//= = = = = = = = = = = = = = = = = = = = = = = =//


51: Empty line in a fenced code block under list items
//- - - - - - - - -//
* This is a list item
```
This is a test

This line will be dropped.
This line will be displayed.
```
//- - - - - - - - -//
<ul>
<li>This is a list item
<pre><code>This is a test

This line will be dropped.
This line will be displayed.
</code></pre>
</li>
</ul>
//= = = = = = = = = = = = = = = = = = = = = = = =//
3 changes: 3 additions & 0 deletions parser/fcode_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ func (b *fencedCodeBlockParser) Continue(node ast.Node, reader text.Reader, pc C
pos, padding := util.IndentPositionPadding(line, reader.LineOffset(), segment.Padding, fdata.indent)
if pos < 0 {
pos = util.FirstNonSpacePosition(line)
if pos < 0 {
pos = 0
}
padding = 0
}
seg := text.NewSegmentPadding(segment.Start+pos, segment.Stop, padding)
Expand Down
53 changes: 53 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,59 @@ func IndentPositionPadding(bs []byte, currentPos, paddingv, width int) (pos, pad
return -1, -1
}

// DedentPosition dedents lines by the given width.
//
// Deprecated: This function has bugs. Use util.IndentPositionPadding and util.FirstNonSpacePosition.
func DedentPosition(bs []byte, currentPos, width int) (pos, padding int) {
if width == 0 {
return 0, 0
}
w := 0
l := len(bs)
i := 0
for ; i < l; i++ {
if bs[i] == '\t' {
w += TabWidth(currentPos + w)
} else if bs[i] == ' ' {
w++
} else {
break
}
}
if w >= width {
return i, w - width
}
return i, 0
}

// DedentPositionPadding dedents lines by the given width.
// This function is mostly same as DedentPosition except this function
// takes account into additional paddings.
//
// Deprecated: This function has bugs. Use util.IndentPositionPadding and util.FirstNonSpacePosition.
func DedentPositionPadding(bs []byte, currentPos, paddingv, width int) (pos, padding int) {
if width == 0 {
return 0, paddingv
}

w := 0
i := 0
l := len(bs)
for ; i < l; i++ {
if bs[i] == '\t' {
w += TabWidth(currentPos + w)
} else if bs[i] == ' ' {
w++
} else {
break
}
}
if w >= width {
return i - paddingv, w - width
}
return i - paddingv, 0
}

// IndentWidth calculate an indent width for the given line.
func IndentWidth(bs []byte, currentPos int) (width, pos int) {
l := len(bs)
Expand Down

0 comments on commit 907eb99

Please sign in to comment.