Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调用 HTML2Markdown 转换 table 失败问题 #70

Closed
degbug opened this issue Jun 12, 2020 · 5 comments
Closed

调用 HTML2Markdown 转换 table 失败问题 #70

degbug opened this issue Jun 12, 2020 · 5 comments
Assignees

Comments

@degbug
Copy link

degbug commented Jun 12, 2020

请先看《提问的智慧》,并尝试到黑客派搜寻资料解决问题。


描述问题

HTML2Markdown 表格转换失败问题

你好,我调用lute将html表格转换成md,报了panic: runtime error: invalid memory address or nil pointer dereference
的错误,我对go不太了解,不知道问题出在哪里

我的代码如下:

package main

import (
	"fmt"

	"github.com/88250/lute"
)

func main() {
	luteEngine := lute.New() // GFM support and Chinese context optimization have been enabled by default
	md, _ := luteEngine.HTML2Markdown(`<html>
	<body>
	
	<table border="1">
	  <tr>
		<th>Month</th>
		<th>Savings</th>
	  </tr>
	  <tr>
		<td>January</td>
		<td>$100</td>
	  </tr>
	</table>
	
	</body>
	</html>	
	`)
	fmt.Println(md)
	// <p><strong>Lute</strong> - A structured Markdown engine.</p>
}

错误信息:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x12c8747]

goroutine 1 [running]:
github.com/88250/lute.(*Lute).genASTByDOM(0xc0000b0f80, 0xc00014c620, 0xc000074ff0)
	/Users/degbug/go/src/github.com/88250/lute/h2m.go:312 +0x3ac7
github.com/88250/lute.(*Lute).HTML2Markdown(0xc0000b0f80, 0x1385515, 0xae, 0xc0000b0f80, 0xc00008c058, 0x0, 0x0)
	/Users/degbug/go/src/github.com/88250/lute/h2m.go:44 +0x1eb
main.main()
	/Users/degbug/github/go_test/md/test.go:11 +0x59
exit status 2

期待的结果

可以转换成功

截屏或录像

其他信息

请提供其他附加信息帮助我们诊断问题。

@88250
Copy link
Owner

88250 commented Jun 12, 2020

似乎是因为表格 HTML 没有 theadtbody,稍后会改进解析,如果没有表头、表身则默认取第一行 tr 为表头。

@88250 88250 self-assigned this Jun 12, 2020
@degbug
Copy link
Author

degbug commented Jun 12, 2020

@88250 谢谢你的回答,我在table中添加了thead和tbody,还是报一样的错误:如下:

package main

import (
	"fmt"

	"github.com/88250/lute"
)

func main() {
	luteEngine := lute.New() // GFM support and Chinese context optimization have been enabled by default
	md, _ := luteEngine.HTML2Markdown(`
<html>
<body>

        <table>
                <thead>
                        <tr>
                                <th>Month</th>
                                <th>Savings</th>
                        </tr>
				</thead>
                <tbody>
                        <tr>
                                <td>January</td>
                                <td>$100</td>
                        </tr>
                        <tr>
                                <td>February</td>
                                <td>$80</td>
                        </tr>
                </tbody>
        </table>
</body>
</html>
	`)
	fmt.Println(md)
	// <p><strong>Lute</strong> - A structured Markdown engine.</p>
}

错误:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x12c8747]

goroutine 1 [running]:
github.com/88250/lute.(*Lute).genASTByDOM(0xc00006e680, 0xc0001805b0, 0xc0005a08a0)
	/Users/degbug/go/src/github.com/88250/lute/h2m.go:312 +0x3ac7
github.com/88250/lute.(*Lute).HTML2Markdown(0xc00006e680, 0x1388d86, 0x153, 0x1, 0x1, 0x154, 0x0)
	/Users/degbug/go/src/github.com/88250/lute/h2m.go:44 +0x1eb
main.main()
	/Users/degbug/github/go_test/md/test.go:37 +0xd2
exit status 2

@88250
Copy link
Owner

88250 commented Jun 12, 2020

刚刚修复了一次,版本号 v1.4.6 麻烦更新试试,谢谢!

@88250 88250 changed the title 调用HTML2Markdown 转换table失败问题 调用 HTML2Markdown 转换 table 失败问题 Jun 12, 2020
@degbug
Copy link
Author

degbug commented Jun 12, 2020

试了,已经可以了

@88250
Copy link
Owner

88250 commented Jun 12, 2020

好的,如果还有其他问题请开 issue 继续反馈,谢谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants