Store cell alignment in own type instead of int
This commit is contained in:
parent
67f85cf540
commit
4ba991937b
6
block.go
6
block.go
|
|
@ -786,7 +786,7 @@ func isBackslashEscaped(data []byte, i int) bool {
|
|||
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 @@ func (p *parser) tableHeader(data []byte) (size int, columns []int) {
|
|||
colCount--
|
||||
}
|
||||
|
||||
columns = make([]int, colCount)
|
||||
columns = make([]CellAlignFlags, colCount)
|
||||
|
||||
// move on to the header underline
|
||||
i++
|
||||
|
|
@ -890,7 +890,7 @@ func (p *parser) tableHeader(data []byte) (size int, columns []int) {
|
|||
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
|
||||
|
||||
|
|
|
|||
8
html.go
8
html.go
|
|
@ -334,7 +334,7 @@ func (r *HTML) BlockQuote(text []byte) {
|
|||
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 @@ func leadingNewline(out *bytes.Buffer) {
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ func (r *HTML) TableHeaderCell(out *bytes.Buffer, text []byte, align int) {
|
|||
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 @@ func skipParagraphTags(node *Node) bool {
|
|||
return grandparent.Type == List && tightOrTerm
|
||||
}
|
||||
|
||||
func cellAlignment(align int) string {
|
||||
func cellAlignment(align CellAlignFlags) string {
|
||||
switch align {
|
||||
case TableAlignmentLeft:
|
||||
return "left"
|
||||
|
|
|
|||
6
latex.go
6
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 @@ func (r *Latex) TableRow(text []byte) {
|
|||
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(" & ")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ const (
|
|||
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 @@ type Renderer interface {
|
|||
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)
|
||||
|
|
|
|||
6
node.go
6
node.go
|
|
@ -106,10 +106,8 @@ type Node struct {
|
|||
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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue