-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_table.go
94 lines (78 loc) · 2.49 KB
/
mod_table.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package white600
import "strings"
// tableAlign ... : --- :
var tableAlign = map[[2]bool]string{
{true, false}: "right", // : ---
{false, true}: "left", // --- :
{true, true}: "center", // : --- :
{false, false}: "center", // ---
}
// convTableHead ...make align
func (data *MarkdownInfo) convTableHead() {
// 次行の情報が必須なので無ければエラー扱い
if len(data.markdown) == 1 {
return
}
// align
alignLine := strings.Split(data.currentData.nextLine, "|")
data.markdown = append([]string{data.markdown[0]}, data.markdown[2:]...) // 位置指定の行を消す
alignLine = alignLine[1 : len(alignLine)-1]
for _, v := range alignLine {
data.options.tableAlign = append(data.options.tableAlign, tableAlign[[2]bool{string(v[len(v)-1]) == ":", string(v[0]) == ":"}])
}
// テーブルヘッダの開始
data.html = append(data.html, "<table><thead>")
// テーブルヘッダを解析
data.tableGenerate("th")
// open <table><thead>
//data.markdownLines[0] = ("<table><thead>" + data.markdownLines[0])
}
// closeTableHead ...if table is close
func (data *MarkdownInfo) closeTableHead() {
if data.currentData.lineType != typeTableBody {
data.shiftLine()
data.html = append(data.html, "</thead></table>")
data.options.tableAlign = nil
}
}
// convTableBody ...table generation
func (data *MarkdownInfo) convTableBody() {
// <tbody>
if data.currentData.isNewBlock {
data.html = append(data.html, "</thead><tbody>")
//data.html = append(data.html, data.inlineConv(inner)) // todo インラインの位置をチェック
}
// <tr>
data.tableGenerate("td")
}
// closeTableBody ...
func (data *MarkdownInfo) closeTableBody() {
data.shiftLine()
data.html = append(data.html, "</tbody></table>")
data.options.tableAlign = nil
}
// tableGenerate ...<tr>
func (data *MarkdownInfo) tableGenerate(tagType string) {
// check
var tr = strings.Split(data.currentData.currentLine, "|")
if len(tr)-2 <= 1 || len(tr)-2 != len(data.options.tableAlign) || tr[0] != "" || tr[len(tr)-1] != "" {
return
}
// make
var html []string
html = append(html, "<tr>")
for i, v := range data.options.tableAlign {
inner := data.inlineConv(tr[i+1])
html = append(html, "<")
html = append(html, tagType)
html = append(html, " align='")
html = append(html, v)
html = append(html, "'>")
html = append(html, inner)
html = append(html, "</")
html = append(html, tagType)
html = append(html, ">")
}
html = append(html, "</tr>")
data.html = append(data.html, html...)
}