Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* giteaofficial/main:
  [skip ci] Updated licenses and gitignores
  Fix repo home row-right grow (go-gitea#32763)
  Refactor issue list (go-gitea#32755)
  Fix compare page bug view as anonymous (go-gitea#32754)
  Split issue/pull view router function as multiple smaller functions (go-gitea#32749)
  fix: render job title as commit message (go-gitea#32748)
  Fix typescript errors in Vue files, fix regression in "Recent Commits" chart (go-gitea#32649)
  Refactor LabelEdit (go-gitea#32752)
  [skip ci] Updated translations via Crowdin
  fix(project): add title to project view page (go-gitea#32747)
  [skip ci] Updated translations via Crowdin
  Fix case of .tsbuildinfo in .gitignore (go-gitea#32737)
  Support "merge upstream branch" (Sync fork) (go-gitea#32741)
  Update changelog to add missed changelog (go-gitea#32734)
  GitHub like repo home page (go-gitea#32213)
  Refactor markdown render (go-gitea#32736)
  Make wiki pages visit fast (go-gitea#32732)
  Refactor markdown render (go-gitea#32728)
  Refactor RepoActionView.vue, add `::group::` support (go-gitea#32713)
  • Loading branch information
zjjhot committed Dec 9, 2024
2 parents 5b3d5b9 + 145b583 commit 24b0634
Show file tree
Hide file tree
Showing 115 changed files with 4,640 additions and 2,512 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _testmain.go
*.exe
*.test
*.prof
*.tsbuildInfo
*.tsbuildinfo

*coverage.out
coverage.all
Expand Down
393 changes: 393 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modules/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func Push(ctx context.Context, repoPath string, opts PushOptions) error {
if err != nil {
if strings.Contains(stderr, "non-fast-forward") {
return &ErrPushOutOfDate{StdOut: stdout, StdErr: stderr, Err: err}
} else if strings.Contains(stderr, "! [remote rejected]") {
} else if strings.Contains(stderr, "! [remote rejected]") || strings.Contains(stderr, "! [rejected]") {
err := &ErrPushRejected{StdOut: stdout, StdErr: stderr, Err: err}
err.GenerateMessage()
return err
Expand Down
56 changes: 56 additions & 0 deletions modules/markup/markdown/markdown_attention_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package markdown_test

import (
"strings"
"testing"

"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/svg"

"github.com/stretchr/testify/assert"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

func TestAttention(t *testing.T) {
defer svg.MockIcon("octicon-info")()
defer svg.MockIcon("octicon-light-bulb")()
defer svg.MockIcon("octicon-report")()
defer svg.MockIcon("octicon-alert")()
defer svg.MockIcon("octicon-stop")()

renderAttention := func(attention, icon string) string {
tmpl := `<blockquote class="attention-header attention-{attention}"><p><svg class="attention-icon attention-{attention} svg {icon}" width="16" height="16"></svg><strong class="attention-{attention}">{Attention}</strong></p>`
tmpl = strings.ReplaceAll(tmpl, "{attention}", attention)
tmpl = strings.ReplaceAll(tmpl, "{icon}", icon)
tmpl = strings.ReplaceAll(tmpl, "{Attention}", cases.Title(language.English).String(attention))
return tmpl
}

test := func(input, expected string) {
result, err := markdown.RenderString(markup.NewTestRenderContext(), input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(result)))
}

test(`
> [!NOTE]
> text
`, renderAttention("note", "octicon-info")+"\n<p>text</p>\n</blockquote>")

test(`> [!note]`, renderAttention("note", "octicon-info")+"\n</blockquote>")
test(`> [!tip]`, renderAttention("tip", "octicon-light-bulb")+"\n</blockquote>")
test(`> [!important]`, renderAttention("important", "octicon-report")+"\n</blockquote>")
test(`> [!warning]`, renderAttention("warning", "octicon-alert")+"\n</blockquote>")
test(`> [!caution]`, renderAttention("caution", "octicon-stop")+"\n</blockquote>")

// escaped by mdformat
test(`> \[!NOTE\]`, renderAttention("note", "octicon-info")+"\n</blockquote>")

// legacy GitHub style
test(`> **warning**`, renderAttention("warning", "octicon-alert")+"\n</blockquote>")
}
25 changes: 25 additions & 0 deletions modules/markup/markdown/markdown_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package markdown_test

import (
"testing"

"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
)

func BenchmarkSpecializedMarkdown(b *testing.B) {
// 240856 4719 ns/op
for i := 0; i < b.N; i++ {
markdown.SpecializedMarkdown(&markup.RenderContext{})
}
}

func BenchmarkMarkdownRender(b *testing.B) {
// 23202 50840 ns/op
for i := 0; i < b.N; i++ {
_, _ = markdown.RenderString(markup.NewTestRenderContext(), "https://example.com\n- a\n- b\n")
}
}
227 changes: 227 additions & 0 deletions modules/markup/markdown/markdown_math_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package markdown

import (
"strings"
"testing"

"code.gitea.io/gitea/modules/markup"

"github.com/stretchr/testify/assert"
)

func TestMathRender(t *testing.T) {
const nl = "\n"
testcases := []struct {
testcase string
expected string
}{
{
"$a$",
`<p><code class="language-math is-loading">a</code></p>` + nl,
},
{
"$ a $",
`<p><code class="language-math is-loading">a</code></p>` + nl,
},
{
"$a$ $b$",
`<p><code class="language-math is-loading">a</code> <code class="language-math is-loading">b</code></p>` + nl,
},
{
`\(a\) \(b\)`,
`<p><code class="language-math is-loading">a</code> <code class="language-math is-loading">b</code></p>` + nl,
},
{
`$a$.`,
`<p><code class="language-math is-loading">a</code>.</p>` + nl,
},
{
`.$a$`,
`<p>.$a$</p>` + nl,
},
{
`$a a$b b$`,
`<p>$a a$b b$</p>` + nl,
},
{
`a a$b b`,
`<p>a a$b b</p>` + nl,
},
{
`a$b $a a$b b$`,
`<p>a$b $a a$b b$</p>` + nl,
},
{
"a$x$",
`<p>a$x$</p>` + nl,
},
{
"$x$a",
`<p>$x$a</p>` + nl,
},
{
"$a$ ($b$) [$c$] {$d$}",
`<p><code class="language-math is-loading">a</code> (<code class="language-math is-loading">b</code>) [$c$] {$d$}</p>` + nl,
},
{
"$$a$$",
`<code class="chroma language-math display">a</code>` + nl,
},
{
"$$a$$ test",
`<p><code class="language-math display is-loading">a</code> test</p>` + nl,
},
{
"test $$a$$",
`<p>test <code class="language-math display is-loading">a</code></p>` + nl,
},
{
`foo $x=\$$ bar`,
`<p>foo <code class="language-math is-loading">x=\$</code> bar</p>` + nl,
},
{
`$\text{$b$}$`,
`<p><code class="language-math is-loading">\text{$b$}</code></p>` + nl,
},
}

for _, test := range testcases {
t.Run(test.testcase, func(t *testing.T) {
res, err := RenderString(markup.NewTestRenderContext(), test.testcase)
assert.NoError(t, err)
assert.Equal(t, test.expected, string(res))
})
}
}

func TestMathRenderBlockIndent(t *testing.T) {
testcases := []struct {
name string
testcase string
expected string
}{
{
"indent-0",
`
\[
\alpha
\]
`,
`<pre class="code-block is-loading"><code class="chroma language-math display">
\alpha
</code></pre>
`,
},
{
"indent-1",
`
\[
\alpha
\]
`,
`<pre class="code-block is-loading"><code class="chroma language-math display">
\alpha
</code></pre>
`,
},
{
"indent-2-mismatch",
`
\[
a
b
c
d
\]
`,
`<pre class="code-block is-loading"><code class="chroma language-math display">
a
b
c
d
</code></pre>
`,
},
{
"indent-2",
`
\[
a
b
c
\]
`,
`<pre class="code-block is-loading"><code class="chroma language-math display">
a
b
c
</code></pre>
`,
},
{
"indent-0-oneline",
`$$ x $$
foo`,
`<code class="chroma language-math display"> x </code>
<p>foo</p>
`,
},
{
"indent-3-oneline",
` $$ x $$<SPACE>
foo`,
`<code class="chroma language-math display"> x </code>
<p>foo</p>
`,
},
{
"quote-block",
`
> \[
> a
> \]
> \[
> b
> \]
`,
`<blockquote>
<pre class="code-block is-loading"><code class="chroma language-math display">
a
</code></pre>
<pre class="code-block is-loading"><code class="chroma language-math display">
b
</code></pre>
</blockquote>
`,
},
{
"list-block",
`
1. a
\[
x
\]
2. b`,
`<ol>
<li>a
<pre class="code-block is-loading"><code class="chroma language-math display">
x
</code></pre>
</li>
<li>b</li>
</ol>
`,
},
}

for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
res, err := RenderString(markup.NewTestRenderContext(), strings.ReplaceAll(test.testcase, "<SPACE>", " "))
assert.NoError(t, err)
assert.Equal(t, test.expected, string(res), "unexpected result for test case:\n%s", test.testcase)
})
}
}
Loading

0 comments on commit 24b0634

Please sign in to comment.