/
block-manager.go
67 lines (61 loc) · 1.65 KB
/
block-manager.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
package wikifier
var blockAliases = map[string]string{
"section": "sec",
"paragraph": "p",
"hash": "map",
"format": "fmt",
}
var blockInitializers = map[string]func(name string, b *parserBlock) block{
"main": newMainBlock,
"clear": newClearBlock,
"sec": newSecBlock,
"p": newPBlock,
"map": newMapBlock,
"infobox": newInfobox,
"infosec": newInfosec,
"invisible": newInvisibleBlock,
"list": newListBlock,
"numlist": newNumlistBlock,
"code": newCodeBlock,
"fmt": newFmtBlock,
"html": newHTMLBlock,
"history": newHistoryBlock,
"style": newStyleBlock,
"imagebox": newImagebox,
"image": newImageBlock,
"model": newModelBlock,
"toc": newTocBlock,
}
func newBlock(blockType, blockName, headingID string, blockClasses []string, parentBlock block, parentCatch catch, pos position) block {
if alias, exist := blockAliases[blockType]; exist {
blockType = alias
}
el := newElement("div", blockType)
for _, class := range blockClasses {
el.addClass("!qc-" + class)
}
underlying := &parserBlock{
openPos: pos,
parentB: parentBlock,
parentC: parentCatch,
typ: blockType,
name: blockName,
headingID: headingID,
classes: blockClasses,
element: el,
genericCatch: &genericCatch{},
}
if init, ok := blockInitializers[blockType]; ok {
b := init(blockName, underlying)
// multi
if b.multi() {
underlying.element = newElements(nil)
}
return b
}
return newUnknownBlock(blockName, underlying)
}
func generateBlock(b block, page *Page) HTML {
b.html(page, b.el()) // FIXME: actual page
return b.el().generate()
}