Skip to content

Commit 695bafe

Browse files
committed
Merge remote-tracking branch 'origin/main' into zzc/dev/agit_2
2 parents a5b38fc + bd80225 commit 695bafe

File tree

20 files changed

+121
-54
lines changed

20 files changed

+121
-54
lines changed

docs/content/contributing/guidelines-frontend.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/h
4747
9. Avoid unnecessary `!important` in CSS, add comments to explain why it's necessary if it can't be avoided.
4848
10. Avoid mixing different events in one event listener, prefer to use individual event listeners for every event.
4949
11. Custom event names are recommended to use `ce-` prefix.
50-
12. Prefer using Tailwind CSS which is available via `tw-` prefix, e.g. `tw-relative`. Gitea's helper CSS classes use `gt-` prefix (`gt-word-break`), while Gitea's own private framework-level CSS classes use `g-` prefix (`g-modal-confirm`).
50+
12. Prefer using Tailwind CSS which is available via `tw-` prefix, e.g. `tw-relative`. Gitea's helper CSS classes use `gt-` prefix (`gt-ellipsis`), while Gitea's own private framework-level CSS classes use `g-` prefix (`g-modal-confirm`).
5151
13. Avoid inline scripts & styles as much as possible, it's recommended to put JS code into JS files and use CSS classes. If inline scripts & styles are unavoidable, explain the reason why it can't be avoided.
5252

5353
### Accessibility / ARIA

docs/content/contributing/guidelines-frontend.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ HTML 页面由[Go HTML Template](https://pkg.go.dev/html/template)渲染。
4747
9. 避免在 CSS 中使用不必要的`!important`,如果无法避免,添加注释解释为什么需要它。
4848
10. 避免在一个事件监听器中混合不同的事件,优先为每个事件使用独立的事件监听器。
4949
11. 推荐使用自定义事件名称前缀`ce-`
50-
12. 建议使用 Tailwind CSS,它可以通过 `tw-` 前缀获得,例如 `tw-relative`. Gitea 自身的助手类 CSS 使用 `gt-` 前缀(`gt-word-break`),Gitea 自身的私有框架级 CSS 类使用 `g-` 前缀(`g-modal-confirm`)。
50+
12. 建议使用 Tailwind CSS,它可以通过 `tw-` 前缀获得,例如 `tw-relative`. Gitea 自身的助手类 CSS 使用 `gt-` 前缀(`gt-ellipsis`),Gitea 自身的私有框架级 CSS 类使用 `g-` 前缀(`g-modal-confirm`)。
5151
13. 尽量避免内联脚本和样式,建议将JS代码放入JS文件中并使用CSS类。如果内联脚本和样式不可避免,请解释无法避免的原因。
5252

5353
### 可访问性 / ARIA

modules/markup/markdown/markdown_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,4 +1019,10 @@ func TestAttention(t *testing.T) {
10191019
test(`> [!important]`, renderAttention("important", "octicon-report")+"\n</blockquote>")
10201020
test(`> [!warning]`, renderAttention("warning", "octicon-alert")+"\n</blockquote>")
10211021
test(`> [!caution]`, renderAttention("caution", "octicon-stop")+"\n</blockquote>")
1022+
1023+
// escaped by mdformat
1024+
test(`> \[!NOTE\]`, renderAttention("note", "octicon-info")+"\n</blockquote>")
1025+
1026+
// legacy GitHub style
1027+
test(`> **warning**`, renderAttention("warning", "octicon-alert")+"\n</blockquote>")
10221028
}

modules/markup/markdown/math/block_parser.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@ func (b *blockParser) Open(parent ast.Node, reader text.Reader, pc parser.Contex
3131
return nil, parser.NoChildren
3232
}
3333

34-
dollars := false
34+
var dollars bool
3535
if b.parseDollars && line[pos] == '$' && line[pos+1] == '$' {
3636
dollars = true
37-
} else if line[pos] != '\\' || line[pos+1] != '[' {
37+
} else if line[pos] == '\\' && line[pos+1] == '[' {
38+
if len(line[pos:]) >= 3 && line[pos+2] == '!' && bytes.Contains(line[pos:], []byte(`\]`)) {
39+
// do not process escaped attention block: "> \[!NOTE\]"
40+
return nil, parser.NoChildren
41+
}
42+
dollars = false
43+
} else {
3844
return nil, parser.NoChildren
3945
}
4046

modules/markup/markdown/transform_blockquote.go

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"golang.org/x/text/language"
1616
)
1717

18-
// renderAttention renders a quote marked with i.e. "> **Note**" or "> **Warning**" with a corresponding svg
18+
// renderAttention renders a quote marked with i.e. "> **Note**" or "> [!Warning]" with a corresponding svg
1919
func (r *HTMLRenderer) renderAttention(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
2020
if entering {
2121
n := node.(*Attention)
@@ -37,38 +37,93 @@ func (r *HTMLRenderer) renderAttention(w util.BufWriter, source []byte, node ast
3737
return ast.WalkContinue, nil
3838
}
3939

40-
func (g *ASTTransformer) transformBlockquote(v *ast.Blockquote, reader text.Reader) (ast.WalkStatus, error) {
41-
// We only want attention blockquotes when the AST looks like:
42-
// > Text("[") Text("!TYPE") Text("]")
40+
func (g *ASTTransformer) extractBlockquoteAttentionEmphasis(firstParagraph ast.Node, reader text.Reader) (string, []ast.Node) {
41+
if firstParagraph.ChildCount() < 1 {
42+
return "", nil
43+
}
44+
node1, ok := firstParagraph.FirstChild().(*ast.Emphasis)
45+
if !ok {
46+
return "", nil
47+
}
48+
val1 := string(node1.Text(reader.Source()))
49+
attentionType := strings.ToLower(val1)
50+
if g.attentionTypes.Contains(attentionType) {
51+
return attentionType, []ast.Node{node1}
52+
}
53+
return "", nil
54+
}
4355

44-
// grab these nodes and make sure we adhere to the attention blockquote structure
45-
firstParagraph := v.FirstChild()
46-
g.applyElementDir(firstParagraph)
56+
func (g *ASTTransformer) extractBlockquoteAttention2(firstParagraph ast.Node, reader text.Reader) (string, []ast.Node) {
57+
if firstParagraph.ChildCount() < 2 {
58+
return "", nil
59+
}
60+
node1, ok := firstParagraph.FirstChild().(*ast.Text)
61+
if !ok {
62+
return "", nil
63+
}
64+
node2, ok := node1.NextSibling().(*ast.Text)
65+
if !ok {
66+
return "", nil
67+
}
68+
val1 := string(node1.Segment.Value(reader.Source()))
69+
val2 := string(node2.Segment.Value(reader.Source()))
70+
if strings.HasPrefix(val1, `\[!`) && val2 == `\]` {
71+
attentionType := strings.ToLower(val1[3:])
72+
if g.attentionTypes.Contains(attentionType) {
73+
return attentionType, []ast.Node{node1, node2}
74+
}
75+
}
76+
return "", nil
77+
}
78+
79+
func (g *ASTTransformer) extractBlockquoteAttention3(firstParagraph ast.Node, reader text.Reader) (string, []ast.Node) {
4780
if firstParagraph.ChildCount() < 3 {
48-
return ast.WalkContinue, nil
81+
return "", nil
4982
}
5083
node1, ok := firstParagraph.FirstChild().(*ast.Text)
5184
if !ok {
52-
return ast.WalkContinue, nil
85+
return "", nil
5386
}
5487
node2, ok := node1.NextSibling().(*ast.Text)
5588
if !ok {
56-
return ast.WalkContinue, nil
89+
return "", nil
5790
}
5891
node3, ok := node2.NextSibling().(*ast.Text)
5992
if !ok {
60-
return ast.WalkContinue, nil
93+
return "", nil
6194
}
6295
val1 := string(node1.Segment.Value(reader.Source()))
6396
val2 := string(node2.Segment.Value(reader.Source()))
6497
val3 := string(node3.Segment.Value(reader.Source()))
6598
if val1 != "[" || val3 != "]" || !strings.HasPrefix(val2, "!") {
66-
return ast.WalkContinue, nil
99+
return "", nil
67100
}
68101

69-
// grab attention type from markdown source
70102
attentionType := strings.ToLower(val2[1:])
71-
if !g.attentionTypes.Contains(attentionType) {
103+
if g.attentionTypes.Contains(attentionType) {
104+
return attentionType, []ast.Node{node1, node2, node3}
105+
}
106+
return "", nil
107+
}
108+
109+
func (g *ASTTransformer) transformBlockquote(v *ast.Blockquote, reader text.Reader) (ast.WalkStatus, error) {
110+
// We only want attention blockquotes when the AST looks like:
111+
// > Text("[") Text("!TYPE") Text("]")
112+
// > Text("\[!TYPE") TEXT("\]")
113+
// > Text("**TYPE**")
114+
115+
// grab these nodes and make sure we adhere to the attention blockquote structure
116+
firstParagraph := v.FirstChild()
117+
g.applyElementDir(firstParagraph)
118+
119+
attentionType, processedNodes := g.extractBlockquoteAttentionEmphasis(firstParagraph, reader)
120+
if attentionType == "" {
121+
attentionType, processedNodes = g.extractBlockquoteAttention2(firstParagraph, reader)
122+
}
123+
if attentionType == "" {
124+
attentionType, processedNodes = g.extractBlockquoteAttention3(firstParagraph, reader)
125+
}
126+
if attentionType == "" {
72127
return ast.WalkContinue, nil
73128
}
74129

@@ -88,9 +143,9 @@ func (g *ASTTransformer) transformBlockquote(v *ast.Blockquote, reader text.Read
88143
attentionParagraph.AppendChild(attentionParagraph, NewAttention(attentionType))
89144
attentionParagraph.AppendChild(attentionParagraph, emphasis)
90145
firstParagraph.Parent().InsertBefore(firstParagraph.Parent(), firstParagraph, attentionParagraph)
91-
firstParagraph.RemoveChild(firstParagraph, node1)
92-
firstParagraph.RemoveChild(firstParagraph, node2)
93-
firstParagraph.RemoveChild(firstParagraph, node3)
146+
for _, processed := range processedNodes {
147+
firstParagraph.RemoveChild(firstParagraph, processed)
148+
}
94149
if firstParagraph.ChildCount() == 0 {
95150
firstParagraph.Parent().RemoveChild(firstParagraph.Parent(), firstParagraph)
96151
}

templates/admin/repo/list.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@
4747
<tr>
4848
<td>{{.ID}}</td>
4949
<td>
50-
<a class="gt-word-break" href="{{.Owner.HomeLink}}">{{.Owner.Name}}</a>
50+
<a class="tw-break-anywhere" href="{{.Owner.HomeLink}}">{{.Owner.Name}}</a>
5151
{{if .Owner.Visibility.IsPrivate}}
5252
<span class="text gold">{{svg "octicon-lock"}}</span>
5353
{{end}}
5454
</td>
5555
<td>
56-
<a class="gt-word-break" href="{{.Link}}">{{.Name}}</a>
56+
<a class="tw-break-anywhere" href="{{.Link}}">{{.Name}}</a>
5757
{{if .IsArchived}}
5858
<span class="ui basic label">{{ctx.Locale.Tr "repo.desc.archived"}}</span>
5959
{{end}}

templates/package/content/container.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
{{end}}
5555
{{if .PackageDescriptor.Metadata.ImageLayers}}
5656
<h4 class="ui top attached header">{{ctx.Locale.Tr "packages.container.layers"}}</h4>
57-
<div class="ui attached segment gt-word-break">
57+
<div class="ui attached segment tw-break-anywhere">
5858
<table class="ui very basic compact table">
5959
<tbody>
6060
{{range .PackageDescriptor.Metadata.ImageLayers}}
@@ -80,7 +80,7 @@
8080
{{range $key, $value := .PackageDescriptor.Metadata.Labels}}
8181
<tr>
8282
<td class="top aligned">{{$key}}</td>
83-
<td class="gt-word-break">{{$value}}</td>
83+
<td class="tw-break-anywhere">{{$value}}</td>
8484
</tr>
8585
{{end}}
8686
</tbody>

templates/package/settings.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
{{ctx.Locale.Tr "packages.settings.delete"}}
6060
</div>
6161
<div class="content">
62-
<div class="ui warning message gt-word-break">
62+
<div class="ui warning message tw-break-anywhere">
6363
{{ctx.Locale.Tr "packages.settings.delete.notice" .PackageDescriptor.Package.Name .PackageDescriptor.Version.Version}}
6464
</div>
6565
<form class="ui form" action="{{.Link}}" method="post">

templates/projects/view.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
<div class="divider"{{if .Color}} style="color: {{ContrastColor .Color}} !important"{{end}}></div>
153153
<div class="ui cards" data-url="{{$.Link}}/{{.ID}}" data-project="{{$.Project.ID}}" data-board="{{.ID}}" id="board_{{.ID}}">
154154
{{range (index $.IssuesMap .ID)}}
155-
<div class="issue-card gt-word-break {{if $canWriteProject}}tw-cursor-grab{{end}}" data-issue="{{.ID}}">
155+
<div class="issue-card tw-break-anywhere {{if $canWriteProject}}tw-cursor-grab{{end}}" data-issue="{{.ID}}">
156156
{{template "repo/issue/card" (dict "Issue" . "Page" $)}}
157157
</div>
158158
{{end}}

templates/repo/home.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{{template "base/alert" .}}
66
{{template "repo/code/recently_pushed_new_branches" .}}
77
{{if and (not .HideRepoInfo) (not .IsBlame)}}
8-
<div class="repo-description gt-word-break">
8+
<div class="repo-description tw-break-anywhere">
99
{{- $description := .Repository.DescriptionHTML ctx -}}
1010
{{if $description}}{{$description | RenderCodeBlock}}{{end}}
1111
{{if .Repository.Website}}<a href="{{.Repository.Website}}">{{.Repository.Website}}</a>{{end}}

0 commit comments

Comments
 (0)