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>
|
</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>
|
||||||
|
//= = = = = = = = = = = = = = = = = = = = = = = =//
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue