From 4c0470d24b00445b67a5a0accde8538d8c810730 Mon Sep 17 00:00:00 2001 From: clsr Date: Fri, 25 Aug 2017 15:04:40 +0200 Subject: Make TableBlock extend ContentBlock; add AppendChild to ContainerBlock --- content.go | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) (limited to 'content.go') diff --git a/content.go b/content.go index 6a728f5..dbe0fa4 100644 --- a/content.go +++ b/content.go @@ -28,6 +28,9 @@ type ContainerBlock interface { // Children returns the child blocks. Children() []Block + + // AppendChild adds a new child block to the end of the list of children. + AppendChild(Block) } // ContentBlock represents a block that holds other content blocks. @@ -467,45 +470,12 @@ func parseContentList(p *Parser, block *TokenBlock) (*ListBlock, error) { // TableBlock represents a "table" content block. type TableBlock struct { - rows []Block + ContentBlock } // NewTableBlock creates a new TableBlock. func NewTableBlock() *TableBlock { - return &TableBlock{} -} - -// Name returns the block name "table". -func (t *TableBlock) Name() string { - return "table" -} - -// Args returns the block's nil arguments. -func (t *TableBlock) Args() []string { - return nil -} - -// WriteIndent writes the table header and contents indented by n tabs. -func (t *TableBlock) WriteIndent(w io.Writer, n int) error { - if err := WriteIndent(w, t.Name(), n); err != nil { - return err - } - for _, row := range t.rows { - if err := row.WriteIndent(w, n+1); err != nil { - return err - } - } - return nil -} - -// Children returns the table's rows. -func (t *TableBlock) Children() []Block { - return t.rows -} - -// AppendRow adds a new row to the end of the table. -func (t *TableBlock) AppendRow(row Block) { - t.rows = append(t.rows, row) + return &TableBlock{*NewContentBlock("table", "")} } func (t *TableBlock) parse(p *Parser, block *TokenBlock) (err error) { @@ -526,7 +496,7 @@ func (t *TableBlock) parse(p *Parser, block *TokenBlock) (err error) { err = parseUnknown(p, blk) } if b != nil { - t.AppendRow(b) + t.AppendChild(b) } } else if err = p.Next(); err != nil { break -- cgit