yuin / goldmark

:trophy: A markdown parser written in Go. Easy to extend, standard(CommonMark) compliant, well structured.
MIT License
3.68k stars 255 forks source link

Add Text() retrieval for BaseBlock types #460

Closed cbednarski closed 3 weeks ago

cbednarski commented 3 months ago

I was trying to use the ast to parse code blocks, and noticed that Text() was always returning empty data.

After digging into this a bit I discovered that the BaseNode type only retrieves Text from child nodes. However, the BaseBlock type (used for code and fenced code blocks) does not have children. Instead, it needs its own Text() implementation to enumerate Lines() to retrieve the text segment(s) identified during parsing.

If you would like to verify that the code change resolves the issue, please comment out the new code in ast/block.go and run the tests.

I've also verified this fix against the test program included in #459.

Thanks!

Closes #459