Skip to content

Commit

Permalink
🐛 表格解析异常 Fix #52
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Apr 10, 2020
1 parent da00ea6 commit 1f1dd60
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions javascript/lute.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion javascript/lute.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lute.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/gopherjs/gopherjs/js"
)

const Version = "1.2.8"
const Version = "1.2.9"

// Lute 描述了 Lute 引擎的顶层使用入口。
type Lute struct {
Expand Down
7 changes: 6 additions & 1 deletion parse/paragraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func ParagraphContinue(p *ast.Node, context *Context) int {
return 0
}

func paragraphFinalize(p *ast.Node, context *Context) {
func paragraphFinalize(p *ast.Node, context *Context) (insertTable bool) {
p.Tokens = lex.TrimWhitespace(p.Tokens)

// 尝试解析链接引用定义
Expand Down Expand Up @@ -90,6 +90,10 @@ func paragraphFinalize(p *ast.Node, context *Context) {
if nil != paragraph {
p.Tokens = paragraph.Tokens
p.InsertAfter(table)
// 设置末梢及其状态
table.Close = true
context.Tip = table
return true
} else {
// 将该段落节点转成表节点
p.Type = ast.NodeTable
Expand All @@ -113,4 +117,5 @@ func paragraphFinalize(p *ast.Node, context *Context) {
return
}
}
return
}
7 changes: 5 additions & 2 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (context *Context) closeUnmatchedBlocks() {

// finalize 执行 block 的最终化处理。调用该方法会将 context.Tip 置为 block 的父节点。
func (context *Context) finalize(block *ast.Node, lineNum int) {
var parent = block.Parent
parent := block.Parent
block.Close = true

// 节点最终化处理。比如围栏代码块提取 info 部分;HTML 代码块剔除结尾空格;段落需要解析链接引用定义等。
Expand All @@ -152,7 +152,10 @@ func (context *Context) finalize(block *ast.Node, lineNum int) {
case ast.NodeHTMLBlock:
htmlBlockFinalize(block)
case ast.NodeParagraph:
paragraphFinalize(block, context)
insertTable := paragraphFinalize(block, context)
if insertTable {
return
}
case ast.NodeMathBlock:
mathBlockFinalize(block)
case ast.NodeList:
Expand Down
2 changes: 2 additions & 0 deletions test/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (

var debugTests = []parseTest{

// 表格解析异常 https://github.com/88250/lute/issues/52
{"50", "foo\nname | age |\n---- | ---\n\nbar", "<p>foo</p>\n<table>\n<thead>\n<tr>\n<th>name</th>\n<th>age</th>\n</tr>\n</thead>\n</table>\n<p>bar</p>\n"},
{"49", "foo\n| bar |\n| --- |", "<p>foo</p>\n<table>\n<thead>\n<tr>\n<th>bar</th>\n</tr>\n</thead>\n</table>\n"},

// 自动链接渲染问题 https://github.com/88250/lute/issues/41
Expand Down

0 comments on commit 1f1dd60

Please sign in to comment.