goldmark icon indicating copy to clipboard operation
goldmark copied to clipboard

Convert ast node to markdown

Open wujunyi792 opened this issue 1 year ago • 0 comments

Hi! Is there any way to restore the parsed ast.Node to raw markdown? I need to extract the table from the markdown and convert it into structured data. I wrote the following code to parse the ast node, but I am having trouble extracting the text from the cell.

	ast.Walk(doc, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
		if !entering {
			return ast.WalkContinue, nil
		}

		if table, ok := n.(*ast2.Table); ok {
			for row := table.FirstChild(); row != nil; row = row.NextSibling() {
				if tableRow, ok := row.(*ast2.TableRow); ok {
					var rowData []string
					for cell := tableRow.FirstChild(); cell != nil; cell = cell.NextSibling() {
						// get raw markdown in cell
					}
					fmt.Println(rowData)
				}
			}
		}
		return ast.WalkContinue, nil
	})

Can you give me some advice or demo code?

wujunyi792 avatar May 19 '25 08:05 wujunyi792