From 7ee652de2bad9c4326fddefb057fd1345944b713 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 19 May 2023 22:59:50 +0200 Subject: [PATCH 01/10] Add RTL rendering support to Markdown --- modules/markup/markdown/goldmark.go | 4 ++++ modules/markup/sanitizer.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/modules/markup/markdown/goldmark.go b/modules/markup/markdown/goldmark.go index 816e93b700fa4..e25b25a849fb3 100644 --- a/modules/markup/markdown/goldmark.go +++ b/modules/markup/markdown/goldmark.go @@ -69,6 +69,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")) + case *ast.Paragraph: + v.SetAttributeString("dir", []byte("auto")) case *ast.Image: // Images need two things: // @@ -171,6 +174,7 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa v.AppendChild(v, newChild) } } + v.SetAttributeString("dir", []byte("auto")) case *ast.Text: if v.SoftLineBreak() && !v.HardLineBreak() { renderMetas := pc.Get(renderMetasKey).(map[string]string) diff --git a/modules/markup/sanitizer.go b/modules/markup/sanitizer.go index a0c9ee171f699..1b94129c09c65 100644 --- a/modules/markup/sanitizer.go +++ b/modules/markup/sanitizer.go @@ -102,6 +102,9 @@ func createDefaultPolicy() *bluemonday.Policy { // Allow 'style' attribute on text elements. policy.AllowAttrs("style").OnElements("span", "p") + // Allow 'dir' attribute on elements that may contain rtl content. + policy.AllowAttrs("dir").OnElements("span", "div", "p", "ul", "ol", "h1", "h2", "h3", "h4", "h5", "h6") + // Allow 'color' and 'background-color' properties for the style attribute on text elements. policy.AllowStyles("color", "background-color").OnElements("span", "p") From 404761940369878bead194fa5697e5c0d8ad36f9 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 19 May 2023 23:40:25 +0200 Subject: [PATCH 02/10] remove unnecessary sanitizer change --- modules/markup/sanitizer.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/markup/sanitizer.go b/modules/markup/sanitizer.go index 1b94129c09c65..a0c9ee171f699 100644 --- a/modules/markup/sanitizer.go +++ b/modules/markup/sanitizer.go @@ -102,9 +102,6 @@ func createDefaultPolicy() *bluemonday.Policy { // Allow 'style' attribute on text elements. policy.AllowAttrs("style").OnElements("span", "p") - // Allow 'dir' attribute on elements that may contain rtl content. - policy.AllowAttrs("dir").OnElements("span", "div", "p", "ul", "ol", "h1", "h2", "h3", "h4", "h5", "h6") - // Allow 'color' and 'background-color' properties for the style attribute on text elements. policy.AllowStyles("color", "background-color").OnElements("span", "p") From 0c6d07ae4fc05e6b421ac8651483b222e4480da4 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 20 May 2023 03:27:34 +0200 Subject: [PATCH 03/10] make rtl work --- web_src/css/base.css | 1 + web_src/css/markup/content.css | 1 + 2 files changed, 2 insertions(+) diff --git a/web_src/css/base.css b/web_src/css/base.css index 36624ab957628..c3749d7b2faed 100644 --- a/web_src/css/base.css +++ b/web_src/css/base.css @@ -1091,6 +1091,7 @@ a.label, color: var(--color-text); background: var(--color-box-body); border-color: var(--color-secondary); + text-align: start; } .ui.table th, diff --git a/web_src/css/markup/content.css b/web_src/css/markup/content.css index db67ac4263d26..a2bdc1d0f2286 100644 --- a/web_src/css/markup/content.css +++ b/web_src/css/markup/content.css @@ -23,6 +23,7 @@ } .markup .anchor { + float: left; padding-right: 4px; margin-left: -20px; line-height: 1; From ff58f1581b68de33372305b3973161e9d3bd5606 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 20 May 2023 11:51:40 +0200 Subject: [PATCH 04/10] fix test --- tests/integration/user_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/user_test.go b/tests/integration/user_test.go index fa8e6e85c7a3a..65cba1dee3e31 100644 --- a/tests/integration/user_test.go +++ b/tests/integration/user_test.go @@ -250,7 +250,7 @@ func TestGetUserRss(t *testing.T) { title, _ := rssDoc.ChildrenFiltered("title").Html() assert.EqualValues(t, "Feed of "the_1-user.with.all.allowedChars"", title) description, _ := rssDoc.ChildrenFiltered("description").Html() - assert.EqualValues(t, "<p>some <a href="https://commonmark.org/" rel="nofollow">commonmark</a>!</p>\n", description) + assert.EqualValues(t, "<p dir="auto">some <a href="https://commonmark.org/" rel="nofollow">commonmark</a>!</p>\n", description) } } From 1ff6c8f39ae509460bd9dbf225de770ca5be5b65 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 20 May 2023 12:16:59 +0200 Subject: [PATCH 05/10] Update web_src/css/base.css --- web_src/css/base.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/css/base.css b/web_src/css/base.css index c3749d7b2faed..6c6c5381ad73e 100644 --- a/web_src/css/base.css +++ b/web_src/css/base.css @@ -1091,7 +1091,7 @@ a.label, color: var(--color-text); background: var(--color-box-body); border-color: var(--color-secondary); - text-align: start; + text-align: start; /* Override fomantic's `text-align: left` to make RTL work via HTML `dir="auto"` */ } .ui.table th, From 7d24ff5b3dde5a989dc3bde012dbc0fcd31c9f11 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 20 May 2023 12:30:53 +0200 Subject: [PATCH 06/10] fix anchor alignment --- web_src/css/markup/content.css | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web_src/css/markup/content.css b/web_src/css/markup/content.css index a2bdc1d0f2286..9552875cf4553 100644 --- a/web_src/css/markup/content.css +++ b/web_src/css/markup/content.css @@ -26,11 +26,11 @@ float: left; padding-right: 4px; margin-left: -20px; - line-height: 1; color: inherit; } .markup .anchor .svg { + display: inline-block; vertical-align: middle; } @@ -38,6 +38,10 @@ outline: none; } +.markup h1 .anchor { + margin-top: -2px; /* re-align to center */ +} + .markup h1 .anchor .svg, .markup h2 .anchor .svg, .markup h3 .anchor .svg, From d7c77a8f4d1f78ea224cf7f31c6f2451ba94a5a6 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 20 May 2023 12:41:01 +0200 Subject: [PATCH 07/10] remove duplicate rule --- web_src/css/markup/content.css | 1 - 1 file changed, 1 deletion(-) diff --git a/web_src/css/markup/content.css b/web_src/css/markup/content.css index 9552875cf4553..5b2d6ef2441d5 100644 --- a/web_src/css/markup/content.css +++ b/web_src/css/markup/content.css @@ -30,7 +30,6 @@ } .markup .anchor .svg { - display: inline-block; vertical-align: middle; } From 63989e1b483c64a045b33e2d3cfdc0444c7bf9b1 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 20 May 2023 13:17:30 +0200 Subject: [PATCH 08/10] fix TestAPI_RenderGFM --- routers/api/v1/misc/markup_test.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/routers/api/v1/misc/markup_test.go b/routers/api/v1/misc/markup_test.go index 68776613b272a..8a5d54a7689f9 100644 --- a/routers/api/v1/misc/markup_test.go +++ b/routers/api/v1/misc/markup_test.go @@ -115,8 +115,8 @@ func TestAPI_RenderGFM(t *testing.T) { - [[Tips]] - Bezier widget (by @r-lyeh) https://github.com/ocornut/imgui/issues/786`, // rendered - `

Wiki! Enjoy :)

-
    + `

    Wiki! Enjoy :)

    +
    • Links, Language bindings, Engine bindings
    • Tips
    • Bezier widget (by @r-lyeh) https://github.com/ocornut/imgui/issues/786
    • @@ -125,12 +125,12 @@ func TestAPI_RenderGFM(t *testing.T) { // Guard wiki sidebar: special syntax `[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`, // rendered - `

      Guardfile-DSL / Configuring-Guard

      + `

      Guardfile-DSL / Configuring-Guard

      `, // special syntax `[[Name|Link]]`, // rendered - `

      Name

      + `

      Name

      `, // empty ``, @@ -150,11 +150,11 @@ Here are some links to the most important topics. You can find the full list of [[images/icon-bug.png]] `, // rendered - `

      What is Wine Staging?

      -

      Wine Staging on website wine-staging.com.

      - -

      Here are some links to the most important topics. You can find the full list of pages at the sidebar.

      -

      Configuration + `

      What is Wine Staging?

      +

      Wine Staging on website wine-staging.com.

      + +

      Here are some links to the most important topics. You can find the full list of pages at the sidebar.

      +

      Configuration images/icon-bug.png

      `, } @@ -185,12 +185,12 @@ var simpleCases = []string{ // Guard wiki sidebar: special syntax `[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`, // rendered - `

      [[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]

      + `

      [[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]

      `, // special syntax `[[Name|Link]]`, // rendered - `

      [[Name|Link]]

      + `

      [[Name|Link]]

      `, // empty ``, From b6e9b75c6bb8cc0e698cb25378a5ce2a75efea6f Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 20 May 2023 14:11:43 +0200 Subject: [PATCH 09/10] more test fixes --- modules/markup/markdown/markdown_test.go | 102 +++++++++++------------ 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index e81869d7a4436..f10ebf6153452 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 :)

      -
        + `

        Wiki! Enjoy :)

        + -

        See commit 65f1bf27bc

        -

        Ideas and codes

        -
          +

          See commit 65f1bf27bc

          +

          Ideas and codes

          + `, - `

          What is Wine Staging?

          -

          Wine Staging on website wine-staging.com.

          - -

          Here are some links to the most important topics. You can find the full list of pages at the sidebar.

          + `

          What is Wine Staging?

          +

          Wine Staging on website wine-staging.com.

          + +

          Here are some links to the most important topics. You can find the full list of pages at the sidebar.

          @@ -157,22 +157,22 @@ func testAnswers(baseURLContent, baseURLImages string) []string {
          `, - `

          Excelsior JET allows you to create native executables for Windows, Linux and Mac OS X.

          -
            + `

            Excelsior JET allows you to create native executables for Windows, Linux and Mac OS X.

            +
            1. Package your libGDX application
              images/1.png
            2. Perform a test run by hitting the Run! button.
              images/2.png
            -

            More tests

            -

            (from https://www.markdownguide.org/extended-syntax/)

            -

            Checkboxes

            -
              +

              More tests

              +

              (from https://www.markdownguide.org/extended-syntax/)

              +

              Checkboxes

              +
              • unchecked
              • checked
              • still unchecked
              -

              Definition list

              +

              Definition list

              First Term
              This is the definition of the first term.
              @@ -180,27 +180,27 @@ func testAnswers(baseURLContent, baseURLImages string) []string {
              This is one definition of the second term.
              This is another definition of the second term.
              -

              Footnotes

              -

              Here is a simple footnote,1 and here is a longer one.2

              +

              Footnotes

              +

              Here is a simple footnote,1 and here is a longer one.2


              -
                +
                1. -

                  This is the first footnote. ↩︎

                  +

                  This is the first footnote. ↩︎

                2. -

                  Here is one with multiple paragraphs and code.

                  -

                  Indent paragraphs to include them in the footnote.

                  -

                  { my code }

                  -

                  Add as many paragraphs as you like. ↩︎

                  +

                  Here is one with multiple paragraphs and code.

                  +

                  Indent paragraphs to include them in the footnote.

                  +

                  { my code }

                  +

                  Add as many paragraphs as you like. ↩︎

              -`, `
                +`, `
                • If you want to rebase/retry this PR, click this checkbox.

                -

                This PR has been generated by Renovate Bot.

                +

                This PR has been generated by Renovate Bot.

                `, } } @@ -304,12 +304,12 @@ func TestTotal_RenderWiki(t *testing.T) { // Guard wiki sidebar: special syntax `[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`, // rendered - `

                Guardfile-DSL / Configuring-Guard

                + `

                Guardfile-DSL / Configuring-Guard

                `, // special syntax `[[Name|Link]]`, // rendered - `

                Name

                + `

                Name

                `, } @@ -401,7 +401,7 @@ func TestRenderSiblingImages_Issue12925(t *testing.T) { testcase := `![image1](/image1) ![image2](/image2) ` - expected := `

                image1
                + expected := `

                image1
                image2

                ` res, err := RenderRawString(&markup.RenderContext{Ctx: git.DefaultContext}, testcase) @@ -411,7 +411,7 @@ func TestRenderSiblingImages_Issue12925(t *testing.T) { func TestRenderEmojiInLinks_Issue12331(t *testing.T) { testcase := `[Link with emoji :moon: in text](https://gitea.io)` - expected := `

                Link with emoji 🌔 in text

                + expected := `

                Link with emoji 🌔 in text

                ` res, err := RenderString(&markup.RenderContext{Ctx: git.DefaultContext}, testcase) assert.NoError(t, err) @@ -426,23 +426,23 @@ func TestColorPreview(t *testing.T) { }{ { // hex "`#FF0000`", - `

                #FF0000

                ` + nl, + `

                #FF0000

                ` + nl, }, { // rgb "`rgb(16, 32, 64)`", - `

                rgb(16, 32, 64)

                ` + nl, + `

                rgb(16, 32, 64)

                ` + nl, }, { // short hex "This is the color white `#000`", - `

                This is the color white #000

                ` + nl, + `

                This is the color white #000

                ` + nl, }, { // hsl "HSL stands for hue, saturation, and lightness. An example: `hsl(0, 100%, 50%)`.", - `

                HSL stands for hue, saturation, and lightness. An example: hsl(0, 100%, 50%).

                ` + nl, + `

                HSL stands for hue, saturation, and lightness. An example: hsl(0, 100%, 50%).

                ` + nl, }, { // uppercase hsl "HSL stands for hue, saturation, and lightness. An example: `HSL(0, 100%, 50%)`.", - `

                HSL stands for hue, saturation, and lightness. An example: HSL(0, 100%, 50%).

                ` + nl, + `

                HSL stands for hue, saturation, and lightness. An example: HSL(0, 100%, 50%).

                ` + nl, }, } @@ -481,31 +481,31 @@ func TestMathBlock(t *testing.T) { }{ { "$a$", - `

                a

                ` + nl, + `

                a

                ` + nl, }, { "$ a $", - `

                a

                ` + nl, + `

                a

                ` + nl, }, { "$a$ $b$", - `

                a b

                ` + nl, + `

                a b

                ` + nl, }, { `\(a\) \(b\)`, - `

                a b

                ` + nl, + `

                a b

                ` + nl, }, { `$a a$b b$`, - `

                a a$b b

                ` + nl, + `

                a a$b b

                ` + nl, }, { `a a$b b`, - `

                a a$b b

                ` + nl, + `

                a a$b b

                ` + nl, }, { `a$b $a a$b b$`, - `

                a$b a a$b b

                ` + nl, + `

                a$b a a$b b

                ` + nl, }, { "$$a$$", From f91098854727810d1dae2ef84c9a8528dc1a2958 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 20 May 2023 21:08:36 +0800 Subject: [PATCH 10/10] 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 11888b8536353..da16bcd3cb3fe 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 e25b25a849fb3..f03a780900356 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 f10ebf6153452..e81869d7a4436 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 :)

                -
                  + `

                  Wiki! Enjoy :)

                  + -

                  See commit 65f1bf27bc

                  -

                  Ideas and codes

                  -
                    +

                    See commit 65f1bf27bc

                    +

                    Ideas and codes

                    + `, - `

                    What is Wine Staging?

                    -

                    Wine Staging on website wine-staging.com.

                    - -

                    Here are some links to the most important topics. You can find the full list of pages at the sidebar.

                    + `

                    What is Wine Staging?

                    +

                    Wine Staging on website wine-staging.com.

                    + +

                    Here are some links to the most important topics. You can find the full list of pages at the sidebar.

                    @@ -157,22 +157,22 @@ func testAnswers(baseURLContent, baseURLImages string) []string {
                    `, - `

                    Excelsior JET allows you to create native executables for Windows, Linux and Mac OS X.

                    -
                      + `

                      Excelsior JET allows you to create native executables for Windows, Linux and Mac OS X.

                      +
                      1. Package your libGDX application
                        images/1.png
                      2. Perform a test run by hitting the Run! button.
                        images/2.png
                      -

                      More tests

                      -

                      (from https://www.markdownguide.org/extended-syntax/)

                      -

                      Checkboxes

                      -
                        +

                        More tests

                        +

                        (from https://www.markdownguide.org/extended-syntax/)

                        +

                        Checkboxes

                        +
                        • unchecked
                        • checked
                        • still unchecked
                        -

                        Definition list

                        +

                        Definition list

                        First Term
                        This is the definition of the first term.
                        @@ -180,27 +180,27 @@ func testAnswers(baseURLContent, baseURLImages string) []string {
                        This is one definition of the second term.
                        This is another definition of the second term.
                        -

                        Footnotes

                        -

                        Here is a simple footnote,1 and here is a longer one.2

                        +

                        Footnotes

                        +

                        Here is a simple footnote,1 and here is a longer one.2


                        -
                          +
                          1. -

                            This is the first footnote. ↩︎

                            +

                            This is the first footnote. ↩︎

                          2. -

                            Here is one with multiple paragraphs and code.

                            -

                            Indent paragraphs to include them in the footnote.

                            -

                            { my code }

                            -

                            Add as many paragraphs as you like. ↩︎

                            +

                            Here is one with multiple paragraphs and code.

                            +

                            Indent paragraphs to include them in the footnote.

                            +

                            { my code }

                            +

                            Add as many paragraphs as you like. ↩︎

                        -`, `
                          +`, `
                          • If you want to rebase/retry this PR, click this checkbox.

                          -

                          This PR has been generated by Renovate Bot.

                          +

                          This PR has been generated by Renovate Bot.

                          `, } } @@ -304,12 +304,12 @@ func TestTotal_RenderWiki(t *testing.T) { // Guard wiki sidebar: special syntax `[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`, // rendered - `

                          Guardfile-DSL / Configuring-Guard

                          + `

                          Guardfile-DSL / Configuring-Guard

                          `, // special syntax `[[Name|Link]]`, // rendered - `

                          Name

                          + `

                          Name

                          `, } @@ -401,7 +401,7 @@ func TestRenderSiblingImages_Issue12925(t *testing.T) { testcase := `![image1](/image1) ![image2](/image2) ` - expected := `

                          image1
                          + expected := `

                          image1
                          image2

                          ` res, err := RenderRawString(&markup.RenderContext{Ctx: git.DefaultContext}, testcase) @@ -411,7 +411,7 @@ func TestRenderSiblingImages_Issue12925(t *testing.T) { func TestRenderEmojiInLinks_Issue12331(t *testing.T) { testcase := `[Link with emoji :moon: in text](https://gitea.io)` - expected := `

                          Link with emoji 🌔 in text

                          + expected := `

                          Link with emoji 🌔 in text

                          ` res, err := RenderString(&markup.RenderContext{Ctx: git.DefaultContext}, testcase) assert.NoError(t, err) @@ -426,23 +426,23 @@ func TestColorPreview(t *testing.T) { }{ { // hex "`#FF0000`", - `

                          #FF0000

                          ` + nl, + `

                          #FF0000

                          ` + nl, }, { // rgb "`rgb(16, 32, 64)`", - `

                          rgb(16, 32, 64)

                          ` + nl, + `

                          rgb(16, 32, 64)

                          ` + nl, }, { // short hex "This is the color white `#000`", - `

                          This is the color white #000

                          ` + nl, + `

                          This is the color white #000

                          ` + nl, }, { // hsl "HSL stands for hue, saturation, and lightness. An example: `hsl(0, 100%, 50%)`.", - `

                          HSL stands for hue, saturation, and lightness. An example: hsl(0, 100%, 50%).

                          ` + nl, + `

                          HSL stands for hue, saturation, and lightness. An example: hsl(0, 100%, 50%).

                          ` + nl, }, { // uppercase hsl "HSL stands for hue, saturation, and lightness. An example: `HSL(0, 100%, 50%)`.", - `

                          HSL stands for hue, saturation, and lightness. An example: HSL(0, 100%, 50%).

                          ` + nl, + `

                          HSL stands for hue, saturation, and lightness. An example: HSL(0, 100%, 50%).

                          ` + nl, }, } @@ -481,31 +481,31 @@ func TestMathBlock(t *testing.T) { }{ { "$a$", - `

                          a

                          ` + nl, + `

                          a

                          ` + nl, }, { "$ a $", - `

                          a

                          ` + nl, + `

                          a

                          ` + nl, }, { "$a$ $b$", - `

                          a b

                          ` + nl, + `

                          a b

                          ` + nl, }, { `\(a\) \(b\)`, - `

                          a b

                          ` + nl, + `

                          a b

                          ` + nl, }, { `$a a$b b$`, - `

                          a a$b b

                          ` + nl, + `

                          a a$b b

                          ` + nl, }, { `a a$b b`, - `

                          a a$b b

                          ` + nl, + `

                          a a$b b

                          ` + nl, }, { `a$b $a a$b b$`, - `

                          a$b a a$b b

                          ` + nl, + `

                          a$b a a$b b

                          ` + nl, }, { "$$a$$", diff --git a/modules/markup/renderer.go b/modules/markup/renderer.go index f2477f1e9ee9f..0331c3742ab11 100644 --- a/modules/markup/renderer.go +++ b/modules/markup/renderer.go @@ -30,14 +30,16 @@ const ( type ProcessorHelper struct { IsUsernameMentionable func(ctx context.Context, username string) bool + + ElementDir string // the direction of the elements, eg: "ltr", "rtl", "auto", default to no direction attribute } -var processorHelper ProcessorHelper +var DefaultProcessorHelper ProcessorHelper // Init initialize regexps for markdown parsing func Init(ph *ProcessorHelper) { if ph != nil { - processorHelper = *ph + DefaultProcessorHelper = *ph } NewSanitizer() diff --git a/routers/api/v1/misc/markup_test.go b/routers/api/v1/misc/markup_test.go index 8a5d54a7689f9..68776613b272a 100644 --- a/routers/api/v1/misc/markup_test.go +++ b/routers/api/v1/misc/markup_test.go @@ -115,8 +115,8 @@ func TestAPI_RenderGFM(t *testing.T) { - [[Tips]] - Bezier widget (by @r-lyeh) https://github.com/ocornut/imgui/issues/786`, // rendered - `

                          Wiki! Enjoy :)

                          -
                            + `

                            Wiki! Enjoy :)

                            +
                            • Links, Language bindings, Engine bindings
                            • Tips
                            • Bezier widget (by @r-lyeh) https://github.com/ocornut/imgui/issues/786
                            • @@ -125,12 +125,12 @@ func TestAPI_RenderGFM(t *testing.T) { // Guard wiki sidebar: special syntax `[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`, // rendered - `

                              Guardfile-DSL / Configuring-Guard

                              + `

                              Guardfile-DSL / Configuring-Guard

                              `, // special syntax `[[Name|Link]]`, // rendered - `

                              Name

                              + `

                              Name

                              `, // empty ``, @@ -150,11 +150,11 @@ Here are some links to the most important topics. You can find the full list of [[images/icon-bug.png]] `, // rendered - `

                              What is Wine Staging?

                              -

                              Wine Staging on website wine-staging.com.

                              - -

                              Here are some links to the most important topics. You can find the full list of pages at the sidebar.

                              -

                              Configuration + `

                              What is Wine Staging?

                              +

                              Wine Staging on website wine-staging.com.

                              + +

                              Here are some links to the most important topics. You can find the full list of pages at the sidebar.

                              +

                              Configuration images/icon-bug.png

                              `, } @@ -185,12 +185,12 @@ var simpleCases = []string{ // Guard wiki sidebar: special syntax `[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`, // rendered - `

                              [[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]

                              + `

                              [[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]

                              `, // special syntax `[[Name|Link]]`, // rendered - `

                              [[Name|Link]]

                              + `

                              [[Name|Link]]

                              `, // empty ``, diff --git a/services/markup/processorhelper.go b/services/markup/processorhelper.go index 2897f203a90fb..3551f85c4668c 100644 --- a/services/markup/processorhelper.go +++ b/services/markup/processorhelper.go @@ -13,6 +13,7 @@ import ( func ProcessorHelper() *markup.ProcessorHelper { return &markup.ProcessorHelper{ + ElementDir: "auto", // set dir="auto" for necessary (eg:

                              , , etc) tags IsUsernameMentionable: func(ctx context.Context, username string) bool { mentionedUser, err := user.GetUserByName(ctx, username) if err != nil {