mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
parent
fa88006eee
commit
697e44ce88
5 changed files with 51 additions and 6 deletions
|
|
@ -809,3 +809,25 @@ text" /></p>
|
||||||
</ul>
|
</ul>
|
||||||
//= = = = = = = = = = = = = = = = = = = = = = = =//
|
//= = = = = = = = = = = = = = = = = = = = = = = =//
|
||||||
|
|
||||||
|
65: Nested fenced code block with tab
|
||||||
|
//- - - - - - - - -//
|
||||||
|
> ```
|
||||||
|
> 0
|
||||||
|
> ```
|
||||||
|
//- - - - - - - - -//
|
||||||
|
<blockquote>
|
||||||
|
<pre><code> 0
|
||||||
|
</code></pre>
|
||||||
|
</blockquote>
|
||||||
|
//= = = = = = = = = = = = = = = = = = = = = = = =//
|
||||||
|
|
||||||
|
66: EOF should be rendered as a newline with an unclosed block
|
||||||
|
//- - - - - - - - -//
|
||||||
|
> ```
|
||||||
|
> 0
|
||||||
|
//- - - - - - - - -//
|
||||||
|
<blockquote>
|
||||||
|
<pre><code> 0
|
||||||
|
</code></pre>
|
||||||
|
</blockquote>
|
||||||
|
//= = = = = = = = = = = = = = = = = = = = = = = =//
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,13 @@ func (b *blockquoteParser) process(reader text.Reader) bool {
|
||||||
reader.Advance(pos)
|
reader.Advance(pos)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if line[pos] == ' ' || line[pos] == '\t' {
|
|
||||||
pos++
|
|
||||||
}
|
|
||||||
reader.Advance(pos)
|
reader.Advance(pos)
|
||||||
if line[pos-1] == '\t' {
|
if line[pos] == ' ' || line[pos] == '\t' {
|
||||||
reader.SetPadding(2)
|
padding := 0
|
||||||
|
if line[pos] == '\t' {
|
||||||
|
padding = util.TabWidth(reader.LineOffset()) - 1
|
||||||
|
}
|
||||||
|
reader.AdvanceAndSetPadding(1, padding)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -878,10 +878,17 @@ func (p *parser) Parse(reader text.Reader, opts ...ParseOption) ast.Node {
|
||||||
blockReader := text.NewBlockReader(reader.Source(), nil)
|
blockReader := text.NewBlockReader(reader.Source(), nil)
|
||||||
p.walkBlock(root, func(node ast.Node) {
|
p.walkBlock(root, func(node ast.Node) {
|
||||||
p.parseBlock(blockReader, node, pc)
|
p.parseBlock(blockReader, node, pc)
|
||||||
|
lines := node.Lines()
|
||||||
|
if lines != nil && lines.Len() != 0 {
|
||||||
|
s := lines.At(lines.Len() - 1)
|
||||||
|
s.EOB = true
|
||||||
|
lines.Set(lines.Len()-1, s)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
for _, at := range p.astTransformers {
|
for _, at := range p.astTransformers {
|
||||||
at.Transform(root, reader, pc)
|
at.Transform(root, reader, pc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// root.Dump(reader.Source(), 0)
|
// root.Dump(reader.Source(), 0)
|
||||||
return root
|
return root
|
||||||
}
|
}
|
||||||
|
|
@ -1256,4 +1263,5 @@ func (p *parser) parseBlock(block text.BlockReader, parent ast.Node, pc Context)
|
||||||
for _, ip := range p.closeBlockers {
|
for _, ip := range p.closeBlockers {
|
||||||
ip.CloseBlock(parent, block, pc)
|
ip.CloseBlock(parent, block, pc)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package text
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
||||||
"github.com/yuin/goldmark/util"
|
"github.com/yuin/goldmark/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -18,6 +19,9 @@ type Segment struct {
|
||||||
|
|
||||||
// Padding is a padding length of the segment.
|
// Padding is a padding length of the segment.
|
||||||
Padding int
|
Padding int
|
||||||
|
|
||||||
|
// EOB is true if the segment is end of the block.
|
||||||
|
EOB bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSegment return a new Segment.
|
// NewSegment return a new Segment.
|
||||||
|
|
@ -45,7 +49,11 @@ func (t *Segment) Value(buffer []byte) []byte {
|
||||||
}
|
}
|
||||||
result := make([]byte, 0, t.Padding+t.Stop-t.Start+1)
|
result := make([]byte, 0, t.Padding+t.Stop-t.Start+1)
|
||||||
result = append(result, bytes.Repeat(space, t.Padding)...)
|
result = append(result, bytes.Repeat(space, t.Padding)...)
|
||||||
return append(result, buffer[t.Start:t.Stop]...)
|
result = append(result, buffer[t.Start:t.Stop]...)
|
||||||
|
if t.EOB && len(result) > 0 && result[len(result)-1] != '\n' {
|
||||||
|
result = append(result, '\n')
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Len returns a length of the segment.
|
// Len returns a length of the segment.
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,13 @@ func IndentPositionPadding(bs []byte, currentPos, paddingv, width int) (pos, pad
|
||||||
w := 0
|
w := 0
|
||||||
i := 0
|
i := 0
|
||||||
l := len(bs)
|
l := len(bs)
|
||||||
|
p := paddingv
|
||||||
for ; i < l; i++ {
|
for ; i < l; i++ {
|
||||||
|
if p > 0 {
|
||||||
|
p--
|
||||||
|
w++
|
||||||
|
continue
|
||||||
|
}
|
||||||
if bs[i] == '\t' && w < width {
|
if bs[i] == '\t' && w < width {
|
||||||
w += TabWidth(currentPos + w)
|
w += TabWidth(currentPos + w)
|
||||||
} else if bs[i] == ' ' && w < width {
|
} else if bs[i] == ' ' && w < width {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue