| 47 | func (n *baseNode) Type() NodeType { return n.nodeType } |
| 48 | func (n *baseNode) Children() []Node { return n.nodeChildren } |
| 49 | func (n *baseNode) String(depth int) string { |
| 50 | ret := `` |
| 51 | for _, c := range n.Children() { |
| 52 | if n.Type() == ListNode { |
| 53 | ret += c.String(depth - 1) |
| 54 | } else { |
| 55 | ret += c.String(depth + 1) |
| 56 | } |
| 57 | |
| 58 | } |
| 59 | |
| 60 | switch n.Type() { |
| 61 | case DocumentNode: |
| 62 | return activeFormatter.Document(ret, depth) |
| 63 | case HeadingNode: |
| 64 | return activeFormatter.Heading(ret, n.level) |
| 65 | case ParagraphNode: |
| 66 | return activeFormatter.Paragraph(ret, depth) |
| 67 | case HorizontalLineNode: |
| 68 | return activeFormatter.HorizontalLine(n.content, depth) |
| 69 | case HardBreakNode: |
| 70 | return activeFormatter.HardBreak(ret, depth) |
| 71 | case ListNode: |
| 72 | return activeFormatter.List(ret, depth) |
| 73 | case ListItemNode: |
| 74 | return activeFormatter.ListItem(ret, depth) |
| 75 | case TextNode: |
| 76 | return activeFormatter.Text(n.content+ret, depth) |
| 77 | case StrongNode: |
| 78 | return activeFormatter.Strong(ret, depth) |
| 79 | case EmphasisNode: |
| 80 | return activeFormatter.Emphasis(ret, depth) |
| 81 | case SpecialNode: |
| 82 | return activeFormatter.Special(ret, n.level) |
| 83 | default: |
| 84 | return fmt.Sprintf(`[INVALID Node: type=%s depth=%d text=%s]`, n.Type(), depth, n.content+"/"+ret) |
| 85 | } |
| 86 | } |