all repos — grayfriday @ 0c38d23ca25d46a03814024113a488baca6b201c

blackfriday fork with a few changes

Merge pull request #43 from microcosm-cc/master

Cells in THEAD > TR are now TH.
Vytautas Ĺ altenis vytas@rtfb.lt
Wed, 08 Jan 2014 11:46:30 -0800
commit

0c38d23ca25d46a03814024113a488baca6b201c

parent

d0e587acc8a319a3c1613fdf8e08c341f8801e1d

5 files changed, 49 insertions(+), 15 deletions(-)

jump to
M block.goblock.go

@@ -654,7 +654,7 @@ }

// include the newline in data sent to tableRow i++ - p.tableRow(&body, data[rowStart:i], columns) + p.tableRow(&body, data[rowStart:i], columns, false) } p.r.Table(out, header.Bytes(), body.Bytes(), columns)

@@ -771,12 +771,12 @@ if col != colCount {

return } - p.tableRow(out, header, columns) + p.tableRow(out, header, columns, true) size = i + 1 return } -func (p *parser) tableRow(out *bytes.Buffer, data []byte, columns []int) { +func (p *parser) tableRow(out *bytes.Buffer, data []byte, columns []int, header bool) { i, col := 0, 0 var rowWork bytes.Buffer

@@ -806,12 +806,21 @@ }

var cellWork bytes.Buffer p.inline(&cellWork, data[cellStart:cellEnd]) - p.r.TableCell(&rowWork, cellWork.Bytes(), columns[col]) + + if header { + p.r.TableHeaderCell(&rowWork, cellWork.Bytes(), columns[col]) + } else { + p.r.TableCell(&rowWork, cellWork.Bytes(), columns[col]) + } } // pad it out with empty columns to get the right number for ; col < len(columns); col++ { - p.r.TableCell(&rowWork, nil, columns[col]) + if header { + p.r.TableHeaderCell(&rowWork, nil, columns[col]) + } else { + p.r.TableCell(&rowWork, nil, columns[col]) + } } // silently ignore rows with too many cells
M block_test.goblock_test.go

@@ -649,46 +649,46 @@

func TestTable(t *testing.T) { var tests = []string{ "a | b\n---|---\nc | d\n", - "<table>\n<thead>\n<tr>\n<td>a</td>\n<td>b</td>\n</tr>\n</thead>\n\n" + + "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n</tr>\n</thead>\n\n" + "<tbody>\n<tr>\n<td>c</td>\n<td>d</td>\n</tr>\n</tbody>\n</table>\n", "a | b\n---|--\nc | d\n", "<p>a | b\n---|--\nc | d</p>\n", "|a|b|c|d|\n|----|----|----|---|\n|e|f|g|h|\n", - "<table>\n<thead>\n<tr>\n<td>a</td>\n<td>b</td>\n<td>c</td>\n<td>d</td>\n</tr>\n</thead>\n\n" + + "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n<th>d</th>\n</tr>\n</thead>\n\n" + "<tbody>\n<tr>\n<td>e</td>\n<td>f</td>\n<td>g</td>\n<td>h</td>\n</tr>\n</tbody>\n</table>\n", "*a*|__b__|[c](C)|d\n---|---|---|---\ne|f|g|h\n", - "<table>\n<thead>\n<tr>\n<td><em>a</em></td>\n<td><strong>b</strong></td>\n<td><a href=\"C\">c</a></td>\n<td>d</td>\n</tr>\n</thead>\n\n" + + "<table>\n<thead>\n<tr>\n<th><em>a</em></th>\n<th><strong>b</strong></th>\n<th><a href=\"C\">c</a></th>\n<th>d</th>\n</tr>\n</thead>\n\n" + "<tbody>\n<tr>\n<td>e</td>\n<td>f</td>\n<td>g</td>\n<td>h</td>\n</tr>\n</tbody>\n</table>\n", "a|b|c\n---|---|---\nd|e|f\ng|h\ni|j|k|l|m\nn|o|p\n", - "<table>\n<thead>\n<tr>\n<td>a</td>\n<td>b</td>\n<td>c</td>\n</tr>\n</thead>\n\n" + + "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n\n" + "<tbody>\n<tr>\n<td>d</td>\n<td>e</td>\n<td>f</td>\n</tr>\n\n" + "<tr>\n<td>g</td>\n<td>h</td>\n<td></td>\n</tr>\n\n" + "<tr>\n<td>i</td>\n<td>j</td>\n<td>k</td>\n</tr>\n\n" + "<tr>\n<td>n</td>\n<td>o</td>\n<td>p</td>\n</tr>\n</tbody>\n</table>\n", "a|b|c\n---|---|---\n*d*|__e__|f\n", - "<table>\n<thead>\n<tr>\n<td>a</td>\n<td>b</td>\n<td>c</td>\n</tr>\n</thead>\n\n" + + "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n\n" + "<tbody>\n<tr>\n<td><em>d</em></td>\n<td><strong>e</strong></td>\n<td>f</td>\n</tr>\n</tbody>\n</table>\n", "a|b|c|d\n:--|--:|:-:|---\ne|f|g|h\n", - "<table>\n<thead>\n<tr>\n<td align=\"left\">a</td>\n<td align=\"right\">b</td>\n" + - "<td align=\"center\">c</td>\n<td>d</td>\n</tr>\n</thead>\n\n" + + "<table>\n<thead>\n<tr>\n<th align=\"left\">a</th>\n<th align=\"right\">b</th>\n" + + "<th align=\"center\">c</th>\n<th>d</th>\n</tr>\n</thead>\n\n" + "<tbody>\n<tr>\n<td align=\"left\">e</td>\n<td align=\"right\">f</td>\n" + "<td align=\"center\">g</td>\n<td>h</td>\n</tr>\n</tbody>\n</table>\n", "a|b|c\n---|---|---\n", - "<table>\n<thead>\n<tr>\n<td>a</td>\n<td>b</td>\n<td>c</td>\n</tr>\n</thead>\n\n<tbody>\n</tbody>\n</table>\n", + "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n\n<tbody>\n</tbody>\n</table>\n", "a| b|c | d | e\n---|---|---|---|---\nf| g|h | i |j\n", - "<table>\n<thead>\n<tr>\n<td>a</td>\n<td>b</td>\n<td>c</td>\n<td>d</td>\n<td>e</td>\n</tr>\n</thead>\n\n" + + "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n<th>d</th>\n<th>e</th>\n</tr>\n</thead>\n\n" + "<tbody>\n<tr>\n<td>f</td>\n<td>g</td>\n<td>h</td>\n<td>i</td>\n<td>j</td>\n</tr>\n</tbody>\n</table>\n", "a|b\\|c|d\n---|---|---\nf|g\\|h|i\n", - "<table>\n<thead>\n<tr>\n<td>a</td>\n<td>b|c</td>\n<td>d</td>\n</tr>\n</thead>\n\n<tbody>\n<tr>\n<td>f</td>\n<td>g|h</td>\n<td>i</td>\n</tr>\n</tbody>\n</table>\n", + "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b|c</th>\n<th>d</th>\n</tr>\n</thead>\n\n<tbody>\n<tr>\n<td>f</td>\n<td>g|h</td>\n<td>i</td>\n</tr>\n</tbody>\n</table>\n", } doTestsBlock(t, tests, EXTENSION_TABLES) }
M html.gohtml.go

@@ -305,6 +305,23 @@ out.Write(text)

out.WriteString("\n</tr>\n") } +func (options *Html) TableHeaderCell(out *bytes.Buffer, text []byte, align int) { + doubleSpace(out) + switch align { + case TABLE_ALIGNMENT_LEFT: + out.WriteString("<th align=\"left\">") + case TABLE_ALIGNMENT_RIGHT: + out.WriteString("<th align=\"right\">") + case TABLE_ALIGNMENT_CENTER: + out.WriteString("<th align=\"center\">") + default: + out.WriteString("<th>") + } + + out.Write(text) + out.WriteString("</th>") +} + func (options *Html) TableCell(out *bytes.Buffer, text []byte, align int) { doubleSpace(out) switch align {
M latex.golatex.go

@@ -151,6 +151,13 @@ }

out.Write(text) } +func (options *Latex) TableHeaderCell(out *bytes.Buffer, text []byte, align int) { + if out.Len() > 0 { + out.WriteString(" & ") + } + out.Write(text) +} + func (options *Latex) TableCell(out *bytes.Buffer, text []byte, align int) { if out.Len() > 0 { out.WriteString(" & ")
M markdown.gomarkdown.go

@@ -140,6 +140,7 @@ ListItem(out *bytes.Buffer, text []byte, flags int)

Paragraph(out *bytes.Buffer, text func() bool) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) TableRow(out *bytes.Buffer, text []byte) + TableHeaderCell(out *bytes.Buffer, text []byte, flags int) TableCell(out *bytes.Buffer, text []byte, flags int) Footnotes(out *bytes.Buffer, text func() bool) FootnoteItem(out *bytes.Buffer, name, text []byte, flags int)