MCPcopy
hub / github.com/tdewolff/canvas / renderBlock

Method renderBlock

markdown.go:54–179  ·  view source on GitHub ↗
(src []byte, n ast.Node, marginTop float64)

Source from the content-addressed store, hash-verified

52}
53
54func (r *mdRenderer) renderBlock(src []byte, n ast.Node, marginTop float64) (float64, error) {
55 margin := 1.0
56 font := r.roman
57 fontSize := r.fontSize
58 switch v := n.(type) {
59 case *ast.Heading:
60 switch v.Level {
61 case 1:
62 fontSize *= 2.0
63 margin = 0.67
64 case 2:
65 fontSize *= 1.5
66 margin = 0.83
67 case 3:
68 fontSize *= 1.3
69 case 4:
70 margin = 1.33
71 case 5:
72 fontSize *= 0.8
73 margin = 1.67
74 case 6:
75 fontSize *= 0.7
76 margin = 2.33
77 }
78 case *ast.List:
79 if _, ok := n.Parent().(*ast.ListItem); ok {
80 margin = 0.0
81 }
82 case *ast.ListItem:
83 margin = 0.0
84 }
85 margin *= fontSize * mmPerPt
86 if !math.IsInf(marginTop, 0) {
87 r.rect.Y1 -= math.Max(marginTop, margin)
88 }
89
90 switch v := n.(type) {
91 case *ast.List:
92 x0 := r.rect.X0
93 r.rect.X0 += r.faceDefault.Size * 1.5
94
95 spacing := fontSize * mmPerPt * 0.15
96 metrics := r.faceDefault.Metrics()
97 for child := n.FirstChild(); child != nil; child = child.NextSibling() {
98 if child != n.FirstChild() {
99 r.rect.Y1 -= spacing
100 }
101
102 if item, ok := child.(*ast.ListItem); ok {
103 _ = v.Marker
104 if v.Start != 0 {
105 _ = v.Start + item.Offset
106 }
107
108 x := r.rect.X0 - r.faceDefault.Size*1.25
109 y := r.rect.Y1 - metrics.Ascent + metrics.CapHeight/2.0
110 dash := Line(r.faceDefault.Size/2.0, 0.0)
111 style := DefaultStyle

Callers 1

RenderMethod · 0.95

Calls 12

renderInlineMethod · 0.95
ToTextMethod · 0.95
LineFunction · 0.85
NewRichTextFunction · 0.85
MetricsMethod · 0.80
WMethod · 0.80
HMethod · 0.80
RenderPathMethod · 0.65
RenderTextMethod · 0.65
TranslateMethod · 0.45
FaceMethod · 0.45
DotMethod · 0.45

Tested by

no test coverage detected