From f91098854727810d1dae2ef84c9a8528dc1a2958 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 20 May 2023 21:08:36 +0800 Subject: [PATCH] fix tests --- modules/markup/html.go | 2 +- modules/markup/markdown/goldmark.go | 12 ++- modules/markup/markdown/markdown_test.go | 102 +++++++++++------------ modules/markup/renderer.go | 6 +- routers/api/v1/misc/markup_test.go | 22 ++--- services/markup/processorhelper.go | 1 + 6 files changed, 77 insertions(+), 68 deletions(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index 11888b853635..da16bcd3cb3f 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -630,7 +630,7 @@ func mentionProcessor(ctx *RenderContext, node *html.Node) { } mentionedUsername := mention[1:] - if processorHelper.IsUsernameMentionable != nil && processorHelper.IsUsernameMentionable(ctx.Ctx, mentionedUsername) { + if DefaultProcessorHelper.IsUsernameMentionable != nil && DefaultProcessorHelper.IsUsernameMentionable(ctx.Ctx, mentionedUsername) { replaceContent(node, loc.Start, loc.End, createLink(util.URLJoin(setting.AppURL, mentionedUsername), mention, "mention")) node = node.NextSibling.NextSibling } else { diff --git a/modules/markup/markdown/goldmark.go b/modules/markup/markdown/goldmark.go index e25b25a849fb..f03a78090035 100644 --- a/modules/markup/markdown/goldmark.go +++ b/modules/markup/markdown/goldmark.go @@ -47,6 +47,12 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa tocMode = rc.TOC } + applyElementDir := func(n ast.Node) { + if markup.DefaultProcessorHelper.ElementDir != "" { + n.SetAttributeString("dir", []byte(markup.DefaultProcessorHelper.ElementDir)) + } + } + attentionMarkedBlockquotes := make(container.Set[*ast.Blockquote]) _ = ast.Walk(node, func(n ast.Node, entering bool) (ast.WalkStatus, error) { if !entering { @@ -69,9 +75,9 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa header.ID = util.BytesToReadOnlyString(id.([]byte)) } tocList = append(tocList, header) - v.SetAttributeString("dir", []byte("auto")) + applyElementDir(v) case *ast.Paragraph: - v.SetAttributeString("dir", []byte("auto")) + applyElementDir(v) case *ast.Image: // Images need two things: // @@ -174,7 +180,7 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa v.AppendChild(v, newChild) } } - v.SetAttributeString("dir", []byte("auto")) + applyElementDir(v) case *ast.Text: if v.SoftLineBreak() && !v.HardLineBreak() { renderMetas := pc.Get(renderMetasKey).(map[string]string) diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index f10ebf615345..e81869d7a443 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -68,14 +68,14 @@ func TestRender_StandardLinks(t *testing.T) { assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(buffer)) } - googleRendered := `

https://google.com/

` + googleRendered := `

https://google.com/

` test("", googleRendered, googleRendered) lnk := util.URLJoin(AppSubURL, "WikiPage") lnkWiki := util.URLJoin(AppSubURL, "wiki", "WikiPage") test("[WikiPage](WikiPage)", - `

WikiPage

`, - `

WikiPage

`) + `

WikiPage

`, + `

WikiPage

`) } func TestRender_Images(t *testing.T) { @@ -99,38 +99,38 @@ func TestRender_Images(t *testing.T) { test( "!["+title+"]("+url+")", - `

`+title+`

`) + `

`+title+`

`) test( "[["+title+"|"+url+"]]", - `

`+title+`

`) + `

`+title+`

`) test( "[!["+title+"]("+url+")]("+href+")", - `

`+title+`

`) + `

`+title+`

`) url = "/../../.images/src/02/train.jpg" test( "!["+title+"]("+url+")", - `

`+title+`

`) + `

`+title+`

`) test( "[["+title+"|"+url+"]]", - `

`+title+`

`) + `

`+title+`

`) test( "[!["+title+"]("+url+")]("+href+")", - `

`+title+`

`) + `

`+title+`

`) } func testAnswers(baseURLContent, baseURLImages string) []string { return []string{ - `

Wiki! Enjoy :)

-