diff --git a/latex.go b/latex.go index 65a352e..abc7393 100644 --- a/latex.go +++ b/latex.go @@ -359,3 +359,7 @@ func (r *Latex) DocumentHeader() { func (r *Latex) DocumentFooter() { r.w.WriteString("\n\\end{document}\n") } + +func (r *Latex) Render(ast *Node) []byte { + return nil +} diff --git a/markdown.go b/markdown.go index 11deb46..85c76bb 100644 --- a/markdown.go +++ b/markdown.go @@ -206,6 +206,8 @@ type Renderer interface { CopyWrites(processor func()) []byte Write(b []byte) (int, error) GetResult() []byte + + Render(ast *Node) []byte } // Callback functions for inline parsing. One such function is defined @@ -437,8 +439,71 @@ func MarkdownOptions(input []byte, renderer Renderer, opts Options) []byte { } first := firstPass(p, input) - second := secondPass(p, first) - return second + secondPass(p, first) + // walk the tree and finish up some of unfinished blocks: + for p.tip != nil { + p.finalize(p.tip) + } + ForEachNode(p.doc, func(node *Node, entering bool) { + if node.Type == Paragraph || node.Type == Header || node.Type == TableCell { + p.currBlock = node + p.inline(node.content) + node.content = nil + } + }) + p.parseRefsToAST() + return renderer.Render(p.doc) +} + +func (p *parser) parseRefsToAST() { + if p.flags&Footnotes == 0 || len(p.notes) == 0 { + return + } + p.tip = p.doc + finalizeHtmlBlock(p.addBlock(HtmlBlock, []byte(`