mirror of
https://github.com/kovetskiy/mark.git
synced 2025-06-09 08:03:12 +08:00
fix regression after #60
This commit is contained in:
parent
931d9f706a
commit
c17a3d02d0
@ -647,7 +647,7 @@ func newErrorStatusNotOK(request *gopencils.Resource) error {
|
|||||||
|
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"Confluence API returned unexpected status: %v, "+
|
"Confluence API returned unexpected status: %v, "+
|
||||||
"output: %s",
|
"output: %q",
|
||||||
request.Raw.Status, output,
|
request.Raw.Status, output,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package mark
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/kovetskiy/mark/pkg/mark/stdlib"
|
"github.com/kovetskiy/mark/pkg/mark/stdlib"
|
||||||
@ -55,19 +54,20 @@ func (renderer ConfluenceRenderer) RenderNode(
|
|||||||
) bf.WalkStatus {
|
) bf.WalkStatus {
|
||||||
if node.Type == bf.CodeBlock {
|
if node.Type == bf.CodeBlock {
|
||||||
lang := string(node.Info)
|
lang := string(node.Info)
|
||||||
|
|
||||||
renderer.Stdlib.Templates.ExecuteTemplate(
|
renderer.Stdlib.Templates.ExecuteTemplate(
|
||||||
writer,
|
writer,
|
||||||
"ac:code",
|
"ac:code",
|
||||||
struct {
|
struct {
|
||||||
Language string
|
Language string
|
||||||
Collapse string
|
Collapse bool
|
||||||
Title string
|
Title string
|
||||||
Text string
|
Text string
|
||||||
}{
|
}{
|
||||||
ParseLanguage(lang),
|
ParseLanguage(lang),
|
||||||
strconv.FormatBool(strings.Contains(lang, "collapse")),
|
strings.Contains(lang, "collapse"),
|
||||||
ParseTitle(lang),
|
ParseTitle(lang),
|
||||||
string(node.Literal),
|
strings.TrimSuffix(string(node.Literal), "\n"),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -105,17 +105,19 @@ func templates(api *confluence.API) (*template.Template, error) {
|
|||||||
|
|
||||||
// This template is used for rendering code in ```
|
// This template is used for rendering code in ```
|
||||||
`ac:code`: text(
|
`ac:code`: text(
|
||||||
`<ac:structured-macro ac:name="expand">{{printf "\n"}}`,
|
`{{ if .Collapse }}<ac:structured-macro ac:name="expand">{{printf "\n"}}`,
|
||||||
`<ac:parameter ac:name="title">{{ .Title }}</ac:parameter>{{printf "\n"}}`,
|
`{{ if .Title }}<ac:parameter ac:name="title">{{ .Title }}</ac:parameter>{{printf "\n"}}{{ end }}`,
|
||||||
`<ac:rich-text-body>{{printf "\n"}}`,
|
`<ac:rich-text-body>{{printf "\n"}}{{ end }}`,
|
||||||
|
|
||||||
`<ac:structured-macro ac:name="code">{{printf "\n"}}`,
|
`<ac:structured-macro ac:name="code">{{printf "\n"}}`,
|
||||||
`<ac:parameter ac:name="language">{{ .Language }}</ac:parameter>{{printf "\n"}}`,
|
/**/ `<ac:parameter ac:name="language">{{ .Language }}</ac:parameter>{{printf "\n"}}`,
|
||||||
`<ac:parameter ac:name="collapse">{{ .Collapse }}</ac:parameter>{{printf "\n"}}`,
|
/**/ `<ac:parameter ac:name="collapse">{{ .Collapse }}</ac:parameter>{{printf "\n"}}`,
|
||||||
`<ac:parameter ac:name="title">{{ .Title }}</ac:parameter>{{printf "\n"}}`,
|
/**/ `{{ if .Title }}<ac:parameter ac:name="title">{{ .Title }}</ac:parameter>{{printf "\n"}}{{ end }}`,
|
||||||
`<ac:plain-text-body><![CDATA[{{ .Text | cdata }}]]></ac:plain-text-body>{{printf "\n"}}`,
|
/**/ `<ac:plain-text-body><![CDATA[{{ .Text | cdata }}]]></ac:plain-text-body>{{printf "\n"}}`,
|
||||||
`</ac:structured-macro>{{printf "\n"}}`,
|
|
||||||
`</ac:rich-text-body>{{printf "\n"}}`,
|
|
||||||
`</ac:structured-macro>{{printf "\n"}}`,
|
`</ac:structured-macro>{{printf "\n"}}`,
|
||||||
|
|
||||||
|
`{{ if .Collapse }}</ac:rich-text-body>{{printf "\n"}}`,
|
||||||
|
`</ac:structured-macro>{{printf "\n"}}{{ end }}`,
|
||||||
),
|
),
|
||||||
|
|
||||||
`ac:status`: text(
|
`ac:status`: text(
|
||||||
|
56
pkg/mark/testdata/codes.html
vendored
56
pkg/mark/testdata/codes.html
vendored
@ -1,66 +1,38 @@
|
|||||||
<p><code>inline</code></p>
|
<p><code>inline</code></p>
|
||||||
<ac:structured-macro ac:name="expand">
|
|
||||||
<ac:parameter ac:name="title"></ac:parameter>
|
|
||||||
<ac:rich-text-body>
|
|
||||||
<ac:structured-macro ac:name="code">
|
<ac:structured-macro ac:name="code">
|
||||||
<ac:parameter ac:name="language"></ac:parameter>
|
<ac:parameter ac:name="language"></ac:parameter>
|
||||||
<ac:parameter ac:name="collapse">false</ac:parameter>
|
<ac:parameter ac:name="collapse">false</ac:parameter>
|
||||||
<ac:parameter ac:name="title"></ac:parameter>
|
<ac:plain-text-body><![CDATA[some code]]></ac:plain-text-body>
|
||||||
<ac:plain-text-body><![CDATA[some code
|
|
||||||
]]></ac:plain-text-body>
|
|
||||||
</ac:structured-macro>
|
</ac:structured-macro>
|
||||||
</ac:rich-text-body>
|
|
||||||
</ac:structured-macro>
|
|
||||||
<ac:structured-macro ac:name="expand">
|
|
||||||
<ac:parameter ac:name="title"></ac:parameter>
|
|
||||||
<ac:rich-text-body>
|
|
||||||
<ac:structured-macro ac:name="code">
|
<ac:structured-macro ac:name="code">
|
||||||
<ac:parameter ac:name="language">bash</ac:parameter>
|
<ac:parameter ac:name="language">bash</ac:parameter>
|
||||||
<ac:parameter ac:name="collapse">false</ac:parameter>
|
<ac:parameter ac:name="collapse">false</ac:parameter>
|
||||||
<ac:parameter ac:name="title"></ac:parameter>
|
<ac:plain-text-body><![CDATA[code bash]]></ac:plain-text-body>
|
||||||
<ac:plain-text-body><![CDATA[code bash
|
</ac:structured-macro>
|
||||||
|
<ac:structured-macro ac:name="code">
|
||||||
|
<ac:parameter ac:name="language">bash</ac:parameter>
|
||||||
|
<ac:parameter ac:name="collapse">false</ac:parameter>
|
||||||
|
<ac:plain-text-body><![CDATA[with a newline
|
||||||
]]></ac:plain-text-body>
|
]]></ac:plain-text-body>
|
||||||
</ac:structured-macro>
|
</ac:structured-macro>
|
||||||
</ac:rich-text-body>
|
|
||||||
</ac:structured-macro>
|
|
||||||
<ac:structured-macro ac:name="expand">
|
|
||||||
<ac:parameter ac:name="title"></ac:parameter>
|
|
||||||
<ac:rich-text-body>
|
|
||||||
<ac:structured-macro ac:name="code">
|
<ac:structured-macro ac:name="code">
|
||||||
<ac:parameter ac:name="language">unknown</ac:parameter>
|
<ac:parameter ac:name="language">unknown</ac:parameter>
|
||||||
<ac:parameter ac:name="collapse">false</ac:parameter>
|
<ac:parameter ac:name="collapse">false</ac:parameter>
|
||||||
<ac:parameter ac:name="title"></ac:parameter>
|
<ac:plain-text-body><![CDATA[unknown code]]></ac:plain-text-body>
|
||||||
<ac:plain-text-body><![CDATA[unknown code
|
|
||||||
]]></ac:plain-text-body>
|
|
||||||
</ac:structured-macro>
|
|
||||||
</ac:rich-text-body>
|
|
||||||
</ac:structured-macro>
|
</ac:structured-macro>
|
||||||
|
|
||||||
<p>text
|
<p>text
|
||||||
text 2</p>
|
text 2</p>
|
||||||
<ac:structured-macro ac:name="expand">
|
|
||||||
<ac:parameter ac:name="title"></ac:parameter>
|
|
||||||
<ac:rich-text-body>
|
|
||||||
<ac:structured-macro ac:name="code">
|
<ac:structured-macro ac:name="code">
|
||||||
<ac:parameter ac:name="language">unknown</ac:parameter>
|
<ac:parameter ac:name="language">unknown</ac:parameter>
|
||||||
<ac:parameter ac:name="collapse">false</ac:parameter>
|
<ac:parameter ac:name="collapse">false</ac:parameter>
|
||||||
<ac:parameter ac:name="title"></ac:parameter>
|
<ac:plain-text-body><![CDATA[unknown code 2]]></ac:plain-text-body>
|
||||||
<ac:plain-text-body><![CDATA[unknown code 2
|
|
||||||
]]></ac:plain-text-body>
|
|
||||||
</ac:structured-macro>
|
</ac:structured-macro>
|
||||||
</ac:rich-text-body>
|
|
||||||
</ac:structured-macro>
|
|
||||||
<ac:structured-macro ac:name="expand">
|
|
||||||
<ac:parameter ac:name="title">A b c</ac:parameter>
|
|
||||||
<ac:rich-text-body>
|
|
||||||
<ac:structured-macro ac:name="code">
|
<ac:structured-macro ac:name="code">
|
||||||
<ac:parameter ac:name="language">sh</ac:parameter>
|
<ac:parameter ac:name="language">sh</ac:parameter>
|
||||||
<ac:parameter ac:name="collapse">false</ac:parameter>
|
<ac:parameter ac:name="collapse">false</ac:parameter>
|
||||||
<ac:parameter ac:name="title">A b c</ac:parameter>
|
<ac:parameter ac:name="title">A b c</ac:parameter>
|
||||||
<ac:plain-text-body><![CDATA[no-collapse-title
|
<ac:plain-text-body><![CDATA[no-collapse-title]]></ac:plain-text-body>
|
||||||
]]></ac:plain-text-body>
|
|
||||||
</ac:structured-macro>
|
|
||||||
</ac:rich-text-body>
|
|
||||||
</ac:structured-macro>
|
</ac:structured-macro>
|
||||||
<ac:structured-macro ac:name="expand">
|
<ac:structured-macro ac:name="expand">
|
||||||
<ac:parameter ac:name="title">A b c</ac:parameter>
|
<ac:parameter ac:name="title">A b c</ac:parameter>
|
||||||
@ -69,20 +41,16 @@ text 2</p>
|
|||||||
<ac:parameter ac:name="language">bash</ac:parameter>
|
<ac:parameter ac:name="language">bash</ac:parameter>
|
||||||
<ac:parameter ac:name="collapse">true</ac:parameter>
|
<ac:parameter ac:name="collapse">true</ac:parameter>
|
||||||
<ac:parameter ac:name="title">A b c</ac:parameter>
|
<ac:parameter ac:name="title">A b c</ac:parameter>
|
||||||
<ac:plain-text-body><![CDATA[collapse-and-title
|
<ac:plain-text-body><![CDATA[collapse-and-title]]></ac:plain-text-body>
|
||||||
]]></ac:plain-text-body>
|
|
||||||
</ac:structured-macro>
|
</ac:structured-macro>
|
||||||
</ac:rich-text-body>
|
</ac:rich-text-body>
|
||||||
</ac:structured-macro>
|
</ac:structured-macro>
|
||||||
<ac:structured-macro ac:name="expand">
|
<ac:structured-macro ac:name="expand">
|
||||||
<ac:parameter ac:name="title"></ac:parameter>
|
|
||||||
<ac:rich-text-body>
|
<ac:rich-text-body>
|
||||||
<ac:structured-macro ac:name="code">
|
<ac:structured-macro ac:name="code">
|
||||||
<ac:parameter ac:name="language">c</ac:parameter>
|
<ac:parameter ac:name="language">c</ac:parameter>
|
||||||
<ac:parameter ac:name="collapse">true</ac:parameter>
|
<ac:parameter ac:name="collapse">true</ac:parameter>
|
||||||
<ac:parameter ac:name="title"></ac:parameter>
|
<ac:plain-text-body><![CDATA[collapse-no-title]]></ac:plain-text-body>
|
||||||
<ac:plain-text-body><![CDATA[collapse-no-title
|
|
||||||
]]></ac:plain-text-body>
|
|
||||||
</ac:structured-macro>
|
</ac:structured-macro>
|
||||||
</ac:rich-text-body>
|
</ac:rich-text-body>
|
||||||
</ac:structured-macro>
|
</ac:structured-macro>
|
||||||
|
5
pkg/mark/testdata/codes.md
vendored
5
pkg/mark/testdata/codes.md
vendored
@ -7,6 +7,11 @@ some code
|
|||||||
code bash
|
code bash
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
with a newline
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
```unknown
|
```unknown
|
||||||
unknown code
|
unknown code
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user