mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
Fixes #262
This commit is contained in:
parent
0283c9c543
commit
907eb99835
3 changed files with 78 additions and 0 deletions
|
|
@ -649,3 +649,25 @@ b
|
||||||
<p>a <br />
|
<p>a <br />
|
||||||
b</p>
|
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>
|
||||||
|
//= = = = = = = = = = = = = = = = = = = = = = = =//
|
||||||
|
|
|
||||||
|
|
@ -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)
|
pos, padding := util.IndentPositionPadding(line, reader.LineOffset(), segment.Padding, fdata.indent)
|
||||||
if pos < 0 {
|
if pos < 0 {
|
||||||
pos = util.FirstNonSpacePosition(line)
|
pos = util.FirstNonSpacePosition(line)
|
||||||
|
if pos < 0 {
|
||||||
|
pos = 0
|
||||||
|
}
|
||||||
padding = 0
|
padding = 0
|
||||||
}
|
}
|
||||||
seg := text.NewSegmentPadding(segment.Start+pos, segment.Stop, padding)
|
seg := text.NewSegmentPadding(segment.Start+pos, segment.Stop, padding)
|
||||||
|
|
|
||||||
53
util/util.go
53
util/util.go
|
|
@ -180,6 +180,59 @@ func IndentPositionPadding(bs []byte, currentPos, paddingv, width int) (pos, pad
|
||||||
return -1, -1
|
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.
|
// IndentWidth calculate an indent width for the given line.
|
||||||
func IndentWidth(bs []byte, currentPos int) (width, pos int) {
|
func IndentWidth(bs []byte, currentPos int) (width, pos int) {
|
||||||
l := len(bs)
|
l := len(bs)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue