From 5917d8fb1c5782b77a62a5a84d0fa286b8420fe1 Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Fri, 26 Jun 2020 20:05:59 +0200 Subject: [PATCH] Store table separator indices We want to support fat rows in tables - for that we need to know where the separators are. --- org/table.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/org/table.go b/org/table.go index 244f505..924a64f 100644 --- a/org/table.go +++ b/org/table.go @@ -8,8 +8,9 @@ import ( ) type Table struct { - Rows []Row - ColumnInfos []ColumnInfo + Rows []Row + ColumnInfos []ColumnInfo + SeparatorIndices []int } type Row struct { @@ -43,7 +44,7 @@ func lexTable(line string) (token, bool) { } func (d *Document) parseTable(i int, parentStop stopFn) (int, Node) { - rawRows, start := [][]string{}, i + rawRows, separatorIndices, start := [][]string{}, []int{}, i for ; !parentStop(d, i); i++ { if t := d.tokens[i]; t.kind == "tableRow" { rawRow := strings.FieldsFunc(d.tokens[i].content, func(r rune) bool { return r == '|' }) @@ -52,13 +53,14 @@ func (d *Document) parseTable(i int, parentStop stopFn) (int, Node) { } rawRows = append(rawRows, rawRow) } else if t.kind == "tableSeparator" { + separatorIndices = append(separatorIndices, i-start) rawRows = append(rawRows, nil) } else { break } } - table := Table{nil, getColumnInfos(rawRows)} + table := Table{nil, getColumnInfos(rawRows), separatorIndices} for _, rawColumns := range rawRows { row := Row{nil, isSpecialRow(rawColumns)} if len(rawColumns) != 0 {