mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
Fix #333
This commit is contained in:
parent
aaeb9851a6
commit
a87c5778f9
4 changed files with 43 additions and 9 deletions
|
|
@ -253,3 +253,30 @@ foo|bar
|
|||
</thead>
|
||||
</table>
|
||||
//= = = = = = = = = = = = = = = = = = = = = = = =//
|
||||
|
||||
12: A delimiter can not start with more than 3 spaces
|
||||
//- - - - - - - - -//
|
||||
Foo
|
||||
---
|
||||
//- - - - - - - - -//
|
||||
<p>Foo
|
||||
---</p>
|
||||
//= = = = = = = = = = = = = = = = = = = = = = = =//
|
||||
|
||||
13: A delimiter can not start with more than 3 spaces(w/ tabs)
|
||||
OPTIONS: {"enableEscape": true}
|
||||
//- - - - - - - - -//
|
||||
- aaa
|
||||
|
||||
Foo
|
||||
\t\t---
|
||||
//- - - - - - - - -//
|
||||
<ul>
|
||||
<li>
|
||||
<p>aaa</p>
|
||||
<p>Foo
|
||||
---</p>
|
||||
</li>
|
||||
</ul>
|
||||
//= = = = = = = = = = = = = = = = = = = = = = = =//
|
||||
|
||||
|
|
|
|||
|
|
@ -122,6 +122,9 @@ func WithTableCellAlignMethod(a TableCellAlignMethod) TableOption {
|
|||
}
|
||||
|
||||
func isTableDelim(bs []byte) bool {
|
||||
if w, _ := util.IndentWidth(bs, 0); w > 3 {
|
||||
return false
|
||||
}
|
||||
for _, b := range bs {
|
||||
if !(util.IsSpace(b) || b == '-' || b == '|' || b == ':') {
|
||||
return false
|
||||
|
|
@ -243,6 +246,7 @@ func (b *tableParagraphTransformer) parseRow(segment text.Segment, alignments []
|
|||
}
|
||||
|
||||
func (b *tableParagraphTransformer) parseDelimiter(segment text.Segment, reader text.Reader) []ast.Alignment {
|
||||
|
||||
line := segment.Value(reader.Source())
|
||||
if !isTableDelim(line) {
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package parser
|
|||
import (
|
||||
"github.com/yuin/goldmark/ast"
|
||||
"github.com/yuin/goldmark/text"
|
||||
"github.com/yuin/goldmark/util"
|
||||
)
|
||||
|
||||
type paragraphParser struct {
|
||||
|
|
@ -33,9 +34,8 @@ func (b *paragraphParser) Open(parent ast.Node, reader text.Reader, pc Context)
|
|||
}
|
||||
|
||||
func (b *paragraphParser) Continue(node ast.Node, reader text.Reader, pc Context) State {
|
||||
_, segment := reader.PeekLine()
|
||||
segment = segment.TrimLeftSpace(reader.Source())
|
||||
if segment.IsEmpty() {
|
||||
line, segment := reader.PeekLine()
|
||||
if util.IsBlank(line) {
|
||||
return Close
|
||||
}
|
||||
node.Lines().Append(segment)
|
||||
|
|
@ -44,13 +44,14 @@ func (b *paragraphParser) Continue(node ast.Node, reader text.Reader, pc Context
|
|||
}
|
||||
|
||||
func (b *paragraphParser) Close(node ast.Node, reader text.Reader, pc Context) {
|
||||
parent := node.Parent()
|
||||
if parent == nil {
|
||||
// paragraph has been transformed
|
||||
return
|
||||
}
|
||||
lines := node.Lines()
|
||||
if lines.Len() != 0 {
|
||||
// trim leading spaces
|
||||
for i := 0; i < lines.Len(); i++ {
|
||||
l := lines.At(i)
|
||||
lines.Set(i, l.TrimLeftSpace(reader.Source()))
|
||||
}
|
||||
|
||||
// trim trailing spaces
|
||||
length := lines.Len()
|
||||
lastLine := node.Lines().At(length - 1)
|
||||
|
|
|
|||
|
|
@ -899,11 +899,13 @@ func (p *parser) closeBlocks(from, to int, reader text.Reader, pc Context) {
|
|||
blocks := pc.OpenedBlocks()
|
||||
for i := from; i >= to; i-- {
|
||||
node := blocks[i].Node
|
||||
blocks[i].Parser.Close(blocks[i].Node, reader, pc)
|
||||
paragraph, ok := node.(*ast.Paragraph)
|
||||
if ok && node.Parent() != nil {
|
||||
p.transformParagraph(paragraph, reader, pc)
|
||||
}
|
||||
if node.Parent() != nil { // closes only if node has not been transformed
|
||||
blocks[i].Parser.Close(blocks[i].Node, reader, pc)
|
||||
}
|
||||
}
|
||||
if from == len(blocks)-1 {
|
||||
blocks = blocks[0:to]
|
||||
|
|
|
|||
Loading…
Reference in a new issue