Skip to content

Convert ast node to markdown #511

@wujunyi792

Description

@wujunyi792

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions