-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathcontainers.go
88 lines (74 loc) · 1.73 KB
/
containers.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
/*
* Markdown to PDF Converter
* Available at http://github.com/mandolyte/mdtopdf
*
* Copyright © 2018 Cecil New <[email protected]>.
* Distributed under the MIT License.
* See README.md for details.
*
* Dependencies
* This package depends on two other packages:
*
* Blackfriday Markdown Processor
* Available at http://github.com/russross/blackfriday
*
* fpdf - a PDF document generator with high level support for
* text, drawing and images.
* Available at https://github.com/go-pdf/fpdf
*/
package mdtopdf
type listType int
const (
notlist listType = iota
unordered
ordered
definition
)
// This slice of float64 contains the width of each cell
// in the header of a table. These will be the widths used
// in the table body as well.
var cellwidths []float64
var curdatacell int
var fill = false
func (n listType) String() string {
switch n {
case notlist:
return "Not a List"
case unordered:
return "Unordered"
case ordered:
return "Ordered"
case definition:
return "Definition"
}
return ""
}
type containerState struct {
textStyle Styler
leftMargin float64
firstParagraph bool
// populated if node type is a list
listkind listType
itemNumber int // only if an ordered list
// populated if node type is a link
destination string
// populated if table cell
isHeader bool
}
type states struct {
stack []*containerState
}
func (s *states) push(c *containerState) {
s.stack = append(s.stack, c)
}
func (s *states) pop() *containerState {
var x *containerState
x, s.stack = s.stack[len(s.stack)-1], s.stack[:len(s.stack)-1]
return x
}
func (s *states) peek() *containerState {
return s.stack[len(s.stack)-1]
}
func (s *states) parent() *containerState {
return s.stack[len(s.stack)-2]
}