File: writer.go

package info (click to toggle)
golang-github-niklasfasching-go-org 1.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 872 kB
  • sloc: sh: 142; makefile: 42
file content (116 lines) | stat: -rw-r--r-- 2,824 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package org

import "fmt"

// Writer is the interface that is used to export a parsed document into a new format. See Document.Write().
type Writer interface {
	Before(*Document) // Before is called before any nodes are passed to the writer.
	After(*Document)  // After is called after all nodes have been passed to the writer.
	String() string   // String is called at the very end to retrieve the final output.

	WriterWithExtensions() Writer
	WriteNodesAsString(...Node) string

	WriteKeyword(Keyword)
	WriteInclude(Include)
	WriteComment(Comment)
	WriteNodeWithMeta(NodeWithMeta)
	WriteNodeWithName(NodeWithName)
	WriteHeadline(Headline)
	WriteBlock(Block)
	WriteResult(Result)
	WriteLatexBlock(LatexBlock)
	WriteInlineBlock(InlineBlock)
	WriteExample(Example)
	WriteDrawer(Drawer)
	WritePropertyDrawer(PropertyDrawer)
	WriteList(List)
	WriteListItem(ListItem)
	WriteDescriptiveListItem(DescriptiveListItem)
	WriteTable(Table)
	WriteHorizontalRule(HorizontalRule)
	WriteParagraph(Paragraph)
	WriteText(Text)
	WriteEmphasis(Emphasis)
	WriteLatexFragment(LatexFragment)
	WriteStatisticToken(StatisticToken)
	WriteExplicitLineBreak(ExplicitLineBreak)
	WriteLineBreak(LineBreak)
	WriteRegularLink(RegularLink)
	WriteMacro(Macro)
	WriteTimestamp(Timestamp)
	WriteFootnoteLink(FootnoteLink)
	WriteFootnoteDefinition(FootnoteDefinition)
}

func WriteNodes(w Writer, nodes ...Node) {
	w = w.WriterWithExtensions()
	for _, n := range nodes {
		switch n := n.(type) {
		case Keyword:
			w.WriteKeyword(n)
		case Include:
			w.WriteInclude(n)
		case Comment:
			w.WriteComment(n)
		case NodeWithMeta:
			w.WriteNodeWithMeta(n)
		case NodeWithName:
			w.WriteNodeWithName(n)
		case Headline:
			w.WriteHeadline(n)
		case Block:
			w.WriteBlock(n)
		case Result:
			w.WriteResult(n)
		case LatexBlock:
			w.WriteLatexBlock(n)
		case InlineBlock:
			w.WriteInlineBlock(n)
		case Example:
			w.WriteExample(n)
		case Drawer:
			w.WriteDrawer(n)
		case PropertyDrawer:
			w.WritePropertyDrawer(n)
		case List:
			w.WriteList(n)
		case ListItem:
			w.WriteListItem(n)
		case DescriptiveListItem:
			w.WriteDescriptiveListItem(n)
		case Table:
			w.WriteTable(n)
		case HorizontalRule:
			w.WriteHorizontalRule(n)
		case Paragraph:
			w.WriteParagraph(n)
		case Text:
			w.WriteText(n)
		case Emphasis:
			w.WriteEmphasis(n)
		case LatexFragment:
			w.WriteLatexFragment(n)
		case StatisticToken:
			w.WriteStatisticToken(n)
		case ExplicitLineBreak:
			w.WriteExplicitLineBreak(n)
		case LineBreak:
			w.WriteLineBreak(n)
		case RegularLink:
			w.WriteRegularLink(n)
		case Macro:
			w.WriteMacro(n)
		case Timestamp:
			w.WriteTimestamp(n)
		case FootnoteLink:
			w.WriteFootnoteLink(n)
		case FootnoteDefinition:
			w.WriteFootnoteDefinition(n)
		default:
			if n != nil {
				panic(fmt.Sprintf("bad node %T %#v", n, n))
			}
		}
	}
}