This commit is contained in:
Manuel Rüger 2023-01-05 11:30:22 +01:00
parent bde4b70242
commit 8deecfd67a
4 changed files with 40 additions and 15 deletions

View File

@ -89,7 +89,10 @@ func (tracer *tracer) Printf(format string, args ...interface{}) {
func NewAPI(baseURL string, username string, password string) *API { func NewAPI(baseURL string, username string, password string) *API {
var auth *gopencils.BasicAuth var auth *gopencils.BasicAuth
if username != "" { if username != "" {
auth = &gopencils.BasicAuth{username, password} auth = &gopencils.BasicAuth{
Username: username,
Password: password,
}
} }
rest := gopencils.Api(baseURL+"/rest/api", auth) rest := gopencils.Api(baseURL+"/rest/api", auth)
if username == "" { if username == "" {

View File

@ -149,7 +149,7 @@ func SubstituteLinks(markdown []byte, links []LinkSubstitution) []byte {
} }
func parseLinks(markdown string) []markdownLink { func parseLinks(markdown string) []markdownLink {
re := regexp.MustCompile("\\[[^\\]]+\\]\\((([^\\)#]+)?#?([^\\)]+)?)\\)") re := regexp.MustCompile(`\[[^\]]+\]\((([^\)#]+)?#?([^\)]+)?)\)`)
matches := re.FindAllStringSubmatch(markdown, -1) matches := re.FindAllStringSubmatch(markdown, -1)
links := make([]markdownLink, len(matches)) links := make([]markdownLink, len(matches))

View File

@ -176,7 +176,7 @@ func (renderer ConfluenceRenderer) RenderNode(
theme = option theme = option
} }
} }
renderer.Stdlib.Templates.ExecuteTemplate( err := renderer.Stdlib.Templates.ExecuteTemplate(
writer, writer,
"ac:code", "ac:code",
struct { struct {
@ -197,20 +197,46 @@ func (renderer ConfluenceRenderer) RenderNode(
strings.TrimSuffix(string(node.Literal), "\n"), strings.TrimSuffix(string(node.Literal), "\n"),
}, },
) )
if err != nil {
panic(err)
}
return bf.GoToNext return bf.GoToNext
} }
if node.Type == bf.Link && string(node.Destination[0:3]) == "ac:" { if node.Type == bf.Link && string(node.Destination[0:3]) == "ac:" {
if entering { if entering {
writer.Write([]byte("<ac:link><ri:page ri:content-title=\"")) _, err := writer.Write([]byte("<ac:link><ri:page ri:content-title=\""))
if len(node.Destination) < 4 { if err != nil {
writer.Write(node.FirstChild.Literal) panic(err)
} else {
writer.Write(node.Destination[3:])
} }
writer.Write([]byte("\"/><ac:plain-text-link-body><![CDATA["))
writer.Write(node.FirstChild.Literal) if len(node.Destination) < 4 {
writer.Write([]byte("]]></ac:plain-text-link-body></ac:link>")) _, err := writer.Write(node.FirstChild.Literal)
if err != nil {
panic(err)
}
} else {
_, err := writer.Write(node.Destination[3:])
if err != nil {
panic(err)
}
}
_, err = writer.Write([]byte("\"/><ac:plain-text-link-body><![CDATA["))
if err != nil {
panic(err)
}
_, err = writer.Write(node.FirstChild.Literal)
if err != nil {
panic(err)
}
_, err = writer.Write([]byte("]]></ac:plain-text-link-body></ac:link>"))
if err != nil {
panic(err)
}
return bf.SkipChildren return bf.SkipChildren
} }
return bf.GoToNext return bf.GoToNext

View File

@ -14,10 +14,6 @@ const (
NL = "\n" NL = "\n"
) )
func text(lines ...string) string {
return strings.Join(lines, "\n")
}
func TestCompileMarkdown(t *testing.T) { func TestCompileMarkdown(t *testing.T) {
test := assert.New(t) test := assert.New(t)