From c17a3d02d01340607230987ec2253405baed9add Mon Sep 17 00:00:00 2001
From: Egor Kovetskiy
Date: Thu, 4 Feb 2021 12:18:28 +0300
Subject: [PATCH] fix regression after #60
---
pkg/confluence/api.go | 2 +-
pkg/mark/markdown.go | 8 +++---
pkg/mark/stdlib/stdlib.go | 22 +++++++-------
pkg/mark/testdata/codes.html | 56 ++++++++----------------------------
pkg/mark/testdata/codes.md | 5 ++++
5 files changed, 34 insertions(+), 59 deletions(-)
diff --git a/pkg/confluence/api.go b/pkg/confluence/api.go
index 188bfbd..e96f8c9 100644
--- a/pkg/confluence/api.go
+++ b/pkg/confluence/api.go
@@ -647,7 +647,7 @@ func newErrorStatusNotOK(request *gopencils.Resource) error {
return fmt.Errorf(
"Confluence API returned unexpected status: %v, "+
- "output: %s",
+ "output: %q",
request.Raw.Status, output,
)
}
diff --git a/pkg/mark/markdown.go b/pkg/mark/markdown.go
index cd55094..b4f51fa 100644
--- a/pkg/mark/markdown.go
+++ b/pkg/mark/markdown.go
@@ -3,7 +3,6 @@ package mark
import (
"io"
"regexp"
- "strconv"
"strings"
"github.com/kovetskiy/mark/pkg/mark/stdlib"
@@ -55,19 +54,20 @@ func (renderer ConfluenceRenderer) RenderNode(
) bf.WalkStatus {
if node.Type == bf.CodeBlock {
lang := string(node.Info)
+
renderer.Stdlib.Templates.ExecuteTemplate(
writer,
"ac:code",
struct {
Language string
- Collapse string
+ Collapse bool
Title string
Text string
}{
ParseLanguage(lang),
- strconv.FormatBool(strings.Contains(lang, "collapse")),
+ strings.Contains(lang, "collapse"),
ParseTitle(lang),
- string(node.Literal),
+ strings.TrimSuffix(string(node.Literal), "\n"),
},
)
diff --git a/pkg/mark/stdlib/stdlib.go b/pkg/mark/stdlib/stdlib.go
index 15c1d45..053b020 100644
--- a/pkg/mark/stdlib/stdlib.go
+++ b/pkg/mark/stdlib/stdlib.go
@@ -105,17 +105,19 @@ func templates(api *confluence.API) (*template.Template, error) {
// This template is used for rendering code in ```
`ac:code`: text(
- `{{printf "\n"}}`,
- `{{ .Title }}{{printf "\n"}}`,
- `{{printf "\n"}}`,
- `{{printf "\n"}}`,
- `{{ .Language }}{{printf "\n"}}`,
- `{{ .Collapse }}{{printf "\n"}}`,
- `{{ .Title }}{{printf "\n"}}`,
- `{{printf "\n"}}`,
- `{{printf "\n"}}`,
- `{{printf "\n"}}`,
+ `{{ if .Collapse }}{{printf "\n"}}`,
+ `{{ if .Title }}{{ .Title }}{{printf "\n"}}{{ end }}`,
+ `{{printf "\n"}}{{ end }}`,
+
+ `{{printf "\n"}}`,
+ /**/ `{{ .Language }}{{printf "\n"}}`,
+ /**/ `{{ .Collapse }}{{printf "\n"}}`,
+ /**/ `{{ if .Title }}{{ .Title }}{{printf "\n"}}{{ end }}`,
+ /**/ `{{printf "\n"}}`,
`{{printf "\n"}}`,
+
+ `{{ if .Collapse }}{{printf "\n"}}`,
+ `{{printf "\n"}}{{ end }}`,
),
`ac:status`: text(
diff --git a/pkg/mark/testdata/codes.html b/pkg/mark/testdata/codes.html
index fe11812..c2f8f80 100644
--- a/pkg/mark/testdata/codes.html
+++ b/pkg/mark/testdata/codes.html
@@ -1,66 +1,38 @@
inline
-
-
-
false
-
-
+
-
-
-
-
-
bash
false
-
-
+
+
+bash
+false
+
-
-
-
-
-
unknown
false
-
-
-
-
+
text
text 2
-
-
-
unknown
false
-
-
+
-
-
-
-A b c
-
sh
false
A b c
-
-
-
+
A b c
@@ -69,20 +41,16 @@ text 2
bash
true
A b c
-
+
-
c
true
-
-
+
diff --git a/pkg/mark/testdata/codes.md b/pkg/mark/testdata/codes.md
index dd6497e..efedcbc 100644
--- a/pkg/mark/testdata/codes.md
+++ b/pkg/mark/testdata/codes.md
@@ -7,6 +7,11 @@ some code
code bash
```
+```bash
+with a newline
+
+```
+
```unknown
unknown code
```