diff --git a/extension/_test/table.txt b/extension/_test/table.txt
index 2dc26f2..098e578 100644
--- a/extension/_test/table.txt
+++ b/extension/_test/table.txt
@@ -253,3 +253,30 @@ foo|bar
//= = = = = = = = = = = = = = = = = = = = = = = =//
+
+12: A delimiter can not start with more than 3 spaces
+//- - - - - - - - -//
+Foo
+ ---
+//- - - - - - - - -//
+
Foo
+---
+//= = = = = = = = = = = = = = = = = = = = = = = =//
+
+13: A delimiter can not start with more than 3 spaces(w/ tabs)
+ OPTIONS: {"enableEscape": true}
+//- - - - - - - - -//
+- aaa
+
+ Foo
+\t\t---
+//- - - - - - - - -//
+
+//= = = = = = = = = = = = = = = = = = = = = = = =//
+
diff --git a/extension/table.go b/extension/table.go
index c637b99..48d0d68 100644
--- a/extension/table.go
+++ b/extension/table.go
@@ -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
diff --git a/parser/paragraph.go b/parser/paragraph.go
index 2dd2b9a..9d3fa38 100644
--- a/parser/paragraph.go
+++ b/parser/paragraph.go
@@ -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)
diff --git a/parser/parser.go b/parser/parser.go
index c8d8aed..a823692 100644
--- a/parser/parser.go
+++ b/parser/parser.go
@@ -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]