@@ -13,12 +13,24 @@ import (
13
13
// renders FencedCodeBlock nodes.
14
14
type ConfluenceFencedCodeBlockHTMLRender struct {
15
15
html.Config
16
+ MacroContentKeys map [string ]struct {}
16
17
}
17
18
19
+ const (
20
+ LanguageStringConfluenceMacro string = "CONFLUENCE-MACRO"
21
+
22
+ MacroContentKeyPlainTextBody string = "plain-text-body"
23
+ MacroContentKeyRichTextBody string = "rich-text-body"
24
+ )
25
+
18
26
// NewConfluenceFencedCodeBlockHTMLRender returns a new ConfluenceFencedCodeBlockHTMLRender.
19
27
func NewConfluenceFencedCodeBlockHTMLRender (opts ... html.Option ) renderer.NodeRenderer {
20
28
r := & ConfluenceFencedCodeBlockHTMLRender {
21
29
Config : html .NewConfig (),
30
+ MacroContentKeys : map [string ]struct {}{
31
+ MacroContentKeyPlainTextBody : {},
32
+ MacroContentKeyRichTextBody : {},
33
+ },
22
34
}
23
35
for _ , opt := range opts {
24
36
opt .SetHTMLOption (& r .Config )
@@ -40,12 +52,15 @@ func (r *ConfluenceFencedCodeBlockHTMLRender) renderConfluenceFencedCode(w util.
40
52
if language != nil {
41
53
langString = string (language )
42
54
}
43
- if entering {
44
- // If it is a macro create the macro
45
- if langString == "CONFLUENCE-MACRO" {
55
+
56
+ switch langString {
57
+ case LanguageStringConfluenceMacro :
58
+ if entering {
46
59
r .writeMacro (w , source , n )
47
- } else {
48
- // else insert a code-macro
60
+ }
61
+ default :
62
+ if entering {
63
+ // insert a code-macro
49
64
s := `<ac:structured-macro ac:name="code" ac:schema-version="1">`
50
65
s = s + `<ac:parameter ac:name="theme">Confluence</ac:parameter>`
51
66
s = s + `<ac:parameter ac:name="linenumbers">true</ac:parameter>`
@@ -57,11 +72,10 @@ func (r *ConfluenceFencedCodeBlockHTMLRender) renderConfluenceFencedCode(w util.
57
72
s = s + `<ac:plain-text-body><![CDATA[ `
58
73
_ , _ = w .WriteString (s )
59
74
r .writeLines (w , source , n )
75
+ } else {
76
+ s := ` ]]></ac:plain-text-body></ac:structured-macro>`
77
+ _ , _ = w .WriteString (s )
60
78
}
61
- } else if langString != "CONFLUENCE-MACRO" {
62
- // No special handling for the CONFLUENCE-MACRO, just for the code macros
63
- s := ` ]]></ac:plain-text-body></ac:structured-macro>`
64
- _ , _ = w .WriteString (s )
65
79
}
66
80
return ast .WalkContinue , nil
67
81
}
@@ -94,8 +108,14 @@ func (r *ConfluenceFencedCodeBlockHTMLRender) writeMacro(w util.BufWriter, sourc
94
108
value := strings .TrimSpace (keyValue [1 ])
95
109
// If the key was not indented
96
110
if key [0 ] == keyValue [0 ][0 ] {
97
- // we append a new attribute to the macro
98
- macrostart .WriteString (` ac:` + key + `="` + value + `"` )
111
+ _ , isContentKey := r .MacroContentKeys [key ]
112
+ if isContentKey {
113
+ // we append this as a child element
114
+ parameters .WriteString (`<ac:` + key + `>` + value + `</ac:` + key + `>` )
115
+ } else {
116
+ // we append a new attribute to the macro
117
+ macrostart .WriteString (` ac:` + key + `="` + value + `"` )
118
+ }
99
119
} else {
100
120
// It is aparameter to the macro
101
121
parameters .WriteString (`<ac:parameter ac:name="` + key + `">` + value + `</ac:parameter>` )
0 commit comments