This commit is contained in:
yuin 2022-11-12 20:13:03 +09:00
parent aaeb9851a6
commit a87c5778f9
4 changed files with 43 additions and 9 deletions

View file

@ -253,3 +253,30 @@ foo|bar
</thead> </thead>
</table> </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>
//= = = = = = = = = = = = = = = = = = = = = = = =//

View file

@ -122,6 +122,9 @@ func WithTableCellAlignMethod(a TableCellAlignMethod) TableOption {
} }
func isTableDelim(bs []byte) bool { func isTableDelim(bs []byte) bool {
if w, _ := util.IndentWidth(bs, 0); w > 3 {
return false
}
for _, b := range bs { for _, b := range bs {
if !(util.IsSpace(b) || b == '-' || b == '|' || b == ':') { if !(util.IsSpace(b) || b == '-' || b == '|' || b == ':') {
return false 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 { func (b *tableParagraphTransformer) parseDelimiter(segment text.Segment, reader text.Reader) []ast.Alignment {
line := segment.Value(reader.Source()) line := segment.Value(reader.Source())
if !isTableDelim(line) { if !isTableDelim(line) {
return nil return nil

View file

@ -3,6 +3,7 @@ package parser
import ( import (
"github.com/yuin/goldmark/ast" "github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/text" "github.com/yuin/goldmark/text"
"github.com/yuin/goldmark/util"
) )
type paragraphParser struct { 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 { func (b *paragraphParser) Continue(node ast.Node, reader text.Reader, pc Context) State {
_, segment := reader.PeekLine() line, segment := reader.PeekLine()
segment = segment.TrimLeftSpace(reader.Source()) if util.IsBlank(line) {
if segment.IsEmpty() {
return Close return Close
} }
node.Lines().Append(segment) 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) { 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() lines := node.Lines()
if lines.Len() != 0 { 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 // trim trailing spaces
length := lines.Len() length := lines.Len()
lastLine := node.Lines().At(length - 1) lastLine := node.Lines().At(length - 1)

View file

@ -899,11 +899,13 @@ func (p *parser) closeBlocks(from, to int, reader text.Reader, pc Context) {
blocks := pc.OpenedBlocks() blocks := pc.OpenedBlocks()
for i := from; i >= to; i-- { for i := from; i >= to; i-- {
node := blocks[i].Node node := blocks[i].Node
blocks[i].Parser.Close(blocks[i].Node, reader, pc)
paragraph, ok := node.(*ast.Paragraph) paragraph, ok := node.(*ast.Paragraph)
if ok && node.Parent() != nil { if ok && node.Parent() != nil {
p.transformParagraph(paragraph, reader, pc) 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 { if from == len(blocks)-1 {
blocks = blocks[0:to] blocks = blocks[0:to]