Skip to content

Commit 697e44c

Browse files
committed
Fix #464, Fix #465
1 parent fa88006 commit 697e44c

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

_test/extra.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,3 +809,25 @@ text" /></p>
809809
</ul>
810810
//= = = = = = = = = = = = = = = = = = = = = = = =//
811811

812+
65: Nested fenced code block with tab
813+
//- - - - - - - - -//
814+
> ```
815+
> 0
816+
> ```
817+
//- - - - - - - - -//
818+
<blockquote>
819+
<pre><code> 0
820+
</code></pre>
821+
</blockquote>
822+
//= = = = = = = = = = = = = = = = = = = = = = = =//
823+
824+
66: EOF should be rendered as a newline with an unclosed block
825+
//- - - - - - - - -//
826+
> ```
827+
> 0
828+
//- - - - - - - - -//
829+
<blockquote>
830+
<pre><code> 0
831+
</code></pre>
832+
</blockquote>
833+
//= = = = = = = = = = = = = = = = = = = = = = = =//

parser/blockquote.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ func (b *blockquoteParser) process(reader text.Reader) bool {
2828
reader.Advance(pos)
2929
return true
3030
}
31-
if line[pos] == ' ' || line[pos] == '\t' {
32-
pos++
33-
}
3431
reader.Advance(pos)
35-
if line[pos-1] == '\t' {
36-
reader.SetPadding(2)
32+
if line[pos] == ' ' || line[pos] == '\t' {
33+
padding := 0
34+
if line[pos] == '\t' {
35+
padding = util.TabWidth(reader.LineOffset()) - 1
36+
}
37+
reader.AdvanceAndSetPadding(1, padding)
3738
}
3839
return true
3940
}

parser/parser.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,10 +878,17 @@ func (p *parser) Parse(reader text.Reader, opts ...ParseOption) ast.Node {
878878
blockReader := text.NewBlockReader(reader.Source(), nil)
879879
p.walkBlock(root, func(node ast.Node) {
880880
p.parseBlock(blockReader, node, pc)
881+
lines := node.Lines()
882+
if lines != nil && lines.Len() != 0 {
883+
s := lines.At(lines.Len() - 1)
884+
s.EOB = true
885+
lines.Set(lines.Len()-1, s)
886+
}
881887
})
882888
for _, at := range p.astTransformers {
883889
at.Transform(root, reader, pc)
884890
}
891+
885892
// root.Dump(reader.Source(), 0)
886893
return root
887894
}
@@ -1256,4 +1263,5 @@ func (p *parser) parseBlock(block text.BlockReader, parent ast.Node, pc Context)
12561263
for _, ip := range p.closeBlockers {
12571264
ip.CloseBlock(parent, block, pc)
12581265
}
1266+
12591267
}

text/segment.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package text
22

33
import (
44
"bytes"
5+
56
"github.com/yuin/goldmark/util"
67
)
78

@@ -18,6 +19,9 @@ type Segment struct {
1819

1920
// Padding is a padding length of the segment.
2021
Padding int
22+
23+
// EOB is true if the segment is end of the block.
24+
EOB bool
2125
}
2226

2327
// NewSegment return a new Segment.
@@ -45,7 +49,11 @@ func (t *Segment) Value(buffer []byte) []byte {
4549
}
4650
result := make([]byte, 0, t.Padding+t.Stop-t.Start+1)
4751
result = append(result, bytes.Repeat(space, t.Padding)...)
48-
return append(result, buffer[t.Start:t.Stop]...)
52+
result = append(result, buffer[t.Start:t.Stop]...)
53+
if t.EOB && len(result) > 0 && result[len(result)-1] != '\n' {
54+
result = append(result, '\n')
55+
}
56+
return result
4957
}
5058

5159
// Len returns a length of the segment.

util/util.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ func IndentPositionPadding(bs []byte, currentPos, paddingv, width int) (pos, pad
166166
w := 0
167167
i := 0
168168
l := len(bs)
169+
p := paddingv
169170
for ; i < l; i++ {
171+
if p > 0 {
172+
p--
173+
w++
174+
continue
175+
}
170176
if bs[i] == '\t' && w < width {
171177
w += TabWidth(currentPos + w)
172178
} else if bs[i] == ' ' && w < width {

0 commit comments

Comments
 (0)