Store cell alignment in own type instead of int
Vytautas Ĺ altenis vytas@rtfb.lt
Fri, 01 Apr 2016 11:44:59 +0300
5 files changed,
16 insertions(+),
18 deletions(-)
M
block.go
→
block.go
@@ -786,7 +786,7 @@ }
return backslashes&1 == 1 } -func (p *parser) tableHeader(data []byte) (size int, columns []int) { +func (p *parser) tableHeader(data []byte) (size int, columns []CellAlignFlags) { i := 0 colCount := 1 for i = 0; data[i] != '\n'; i++ {@@ -811,7 +811,7 @@ if i > 2 && data[i-1] == '|' && !isBackslashEscaped(data, i-1) {
colCount-- } - columns = make([]int, colCount) + columns = make([]CellAlignFlags, colCount) // move on to the header underline i++@@ -890,7 +890,7 @@ size = i + 1
return } -func (p *parser) tableRow(data []byte, columns []int, header bool) { +func (p *parser) tableRow(data []byte, columns []CellAlignFlags, header bool) { p.addBlock(TableRow, nil) i, col := 0, 0
M
html.go
→
html.go
@@ -334,7 +334,7 @@ r.w.Write(text)
r.w.WriteString("</blockquote>\n") } -func (r *HTML) Table(header []byte, body []byte, columnData []int) { +func (r *HTML) Table(header []byte, body []byte, columnData []CellAlignFlags) { r.w.Newline() r.w.WriteString("<table>\n<thead>\n") r.w.Write(header)@@ -356,7 +356,7 @@ out.WriteByte('\n')
} } -func (r *HTML) TableHeaderCell(out *bytes.Buffer, text []byte, align int) { +func (r *HTML) TableHeaderCell(out *bytes.Buffer, text []byte, align CellAlignFlags) { leadingNewline(out) switch align { case TableAlignmentLeft:@@ -373,7 +373,7 @@ out.Write(text)
out.WriteString("</th>") } -func (r *HTML) TableCell(out *bytes.Buffer, text []byte, align int) { +func (r *HTML) TableCell(out *bytes.Buffer, text []byte, align CellAlignFlags) { leadingNewline(out) switch align { case TableAlignmentLeft:@@ -1057,7 +1057,7 @@ tightOrTerm := grandparent.Tight || node.Parent.ListFlags&ListTypeTerm != 0
return grandparent.Type == List && tightOrTerm } -func cellAlignment(align int) string { +func cellAlignment(align CellAlignFlags) string { switch align { case TableAlignmentLeft: return "left"
M
latex.go
→
latex.go
@@ -128,7 +128,7 @@ func (r *Latex) EndParagraph() {
r.w.WriteString("\n") } -func (r *Latex) Table(header []byte, body []byte, columnData []int) { +func (r *Latex) Table(header []byte, body []byte, columnData []CellAlignFlags) { r.w.WriteString("\n\\begin{tabular}{") for _, elt := range columnData { switch elt {@@ -152,14 +152,14 @@ r.w.WriteString(" \\\\\n")
r.w.Write(text) } -func (r *Latex) TableHeaderCell(out *bytes.Buffer, text []byte, align int) { +func (r *Latex) TableHeaderCell(out *bytes.Buffer, text []byte, align CellAlignFlags) { if out.Len() > 0 { out.WriteString(" & ") } out.Write(text) } -func (r *Latex) TableCell(out *bytes.Buffer, text []byte, align int) { +func (r *Latex) TableCell(out *bytes.Buffer, text []byte, align CellAlignFlags) { if out.Len() > 0 { out.WriteString(" & ") }
M
markdown.go
→
markdown.go
@@ -93,7 +93,7 @@ ListItemBeginningOfList
ListItemEndOfList ) -type TableFlags int +type CellAlignFlags int // These are the possible flag values for the table cell renderer. // Only a single one of these values will be used; they are not ORed together.@@ -180,10 +180,10 @@ EndList(flags ListType)
ListItem(text []byte, flags ListType) BeginParagraph() EndParagraph() - Table(header []byte, body []byte, columnData []int) + Table(header []byte, body []byte, columnData []CellAlignFlags) TableRow(text []byte) - TableHeaderCell(out *bytes.Buffer, text []byte, flags int) - TableCell(out *bytes.Buffer, text []byte, flags int) + TableHeaderCell(out *bytes.Buffer, text []byte, flags CellAlignFlags) + TableCell(out *bytes.Buffer, text []byte, flags CellAlignFlags) BeginFootnotes() EndFootnotes() FootnoteItem(name, text []byte, flags ListType)
M
node.go
→
node.go
@@ -106,10 +106,8 @@ CodeBlockData // If Type == CodeBlock, this holds its properties
LinkData // If Type == Link, this holds link info HeaderID string // If Type == Header, this might hold header ID, if present IsTitleblock bool - IsHeader bool // If Type == TableCell, this tells if it's under the header row - - // TODO: convert the int to a proper type - Align int // If Type == TableCell, this holds the value for align attribute + IsHeader bool // If Type == TableCell, this tells if it's under the header row + Align CellAlignFlags // If Type == TableCell, this holds the value for align attribute } func NewNode(typ NodeType) *Node {