1package org 2 3import "fmt" 4 5// Writer is the interface that is used to export a parsed document into a new format. See Document.Write(). 6type Writer interface { 7 Before(*Document) // Before is called before any nodes are passed to the writer. 8 After(*Document) // After is called after all nodes have been passed to the writer. 9 String() string // String is called at the very end to retrieve the final output. 10 11 WriterWithExtensions() Writer 12 WriteNodesAsString(...Node) string 13 14 WriteKeyword(Keyword) 15 WriteInclude(Include) 16 WriteComment(Comment) 17 WriteNodeWithMeta(NodeWithMeta) 18 WriteNodeWithName(NodeWithName) 19 WriteHeadline(Headline) 20 WriteBlock(Block) 21 WriteResult(Result) 22 WriteInlineBlock(InlineBlock) 23 WriteExample(Example) 24 WriteDrawer(Drawer) 25 WritePropertyDrawer(PropertyDrawer) 26 WriteList(List) 27 WriteListItem(ListItem) 28 WriteDescriptiveListItem(DescriptiveListItem) 29 WriteTable(Table) 30 WriteHorizontalRule(HorizontalRule) 31 WriteParagraph(Paragraph) 32 WriteText(Text) 33 WriteEmphasis(Emphasis) 34 WriteLatexFragment(LatexFragment) 35 WriteStatisticToken(StatisticToken) 36 WriteExplicitLineBreak(ExplicitLineBreak) 37 WriteLineBreak(LineBreak) 38 WriteRegularLink(RegularLink) 39 WriteMacro(Macro) 40 WriteTimestamp(Timestamp) 41 WriteFootnoteLink(FootnoteLink) 42 WriteFootnoteDefinition(FootnoteDefinition) 43} 44 45func WriteNodes(w Writer, nodes ...Node) { 46 w = w.WriterWithExtensions() 47 for _, n := range nodes { 48 switch n := n.(type) { 49 case Keyword: 50 w.WriteKeyword(n) 51 case Include: 52 w.WriteInclude(n) 53 case Comment: 54 w.WriteComment(n) 55 case NodeWithMeta: 56 w.WriteNodeWithMeta(n) 57 case NodeWithName: 58 w.WriteNodeWithName(n) 59 case Headline: 60 w.WriteHeadline(n) 61 case Block: 62 w.WriteBlock(n) 63 case Result: 64 w.WriteResult(n) 65 case InlineBlock: 66 w.WriteInlineBlock(n) 67 case Example: 68 w.WriteExample(n) 69 case Drawer: 70 w.WriteDrawer(n) 71 case PropertyDrawer: 72 w.WritePropertyDrawer(n) 73 case List: 74 w.WriteList(n) 75 case ListItem: 76 w.WriteListItem(n) 77 case DescriptiveListItem: 78 w.WriteDescriptiveListItem(n) 79 case Table: 80 w.WriteTable(n) 81 case HorizontalRule: 82 w.WriteHorizontalRule(n) 83 case Paragraph: 84 w.WriteParagraph(n) 85 case Text: 86 w.WriteText(n) 87 case Emphasis: 88 w.WriteEmphasis(n) 89 case LatexFragment: 90 w.WriteLatexFragment(n) 91 case StatisticToken: 92 w.WriteStatisticToken(n) 93 case ExplicitLineBreak: 94 w.WriteExplicitLineBreak(n) 95 case LineBreak: 96 w.WriteLineBreak(n) 97 case RegularLink: 98 w.WriteRegularLink(n) 99 case Macro: 100 w.WriteMacro(n) 101 case Timestamp: 102 w.WriteTimestamp(n) 103 case FootnoteLink: 104 w.WriteFootnoteLink(n) 105 case FootnoteDefinition: 106 w.WriteFootnoteDefinition(n) 107 default: 108 if n != nil { 109 panic(fmt.Sprintf("bad node %T %#v", n, n)) 110 } 111 } 112 } 113} 114