Skip to content

Commit 5bc030e

Browse files
authored
Fix various UI bugs (#32821)
1 parent 887928e commit 5bc030e

File tree

7 files changed

+47
-30
lines changed

7 files changed

+47
-30
lines changed

modules/markup/markdown/markdown_math_test.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ func TestMathRender(t *testing.T) {
2020
}{
2121
{
2222
"$a$",
23-
`<p><code class="language-math is-loading">a</code></p>` + nl,
23+
`<p><code class="language-math">a</code></p>` + nl,
2424
},
2525
{
2626
"$ a $",
27-
`<p><code class="language-math is-loading">a</code></p>` + nl,
27+
`<p><code class="language-math">a</code></p>` + nl,
2828
},
2929
{
3030
"$a$ $b$",
31-
`<p><code class="language-math is-loading">a</code> <code class="language-math is-loading">b</code></p>` + nl,
31+
`<p><code class="language-math">a</code> <code class="language-math">b</code></p>` + nl,
3232
},
3333
{
3434
`\(a\) \(b\)`,
35-
`<p><code class="language-math is-loading">a</code> <code class="language-math is-loading">b</code></p>` + nl,
35+
`<p><code class="language-math">a</code> <code class="language-math">b</code></p>` + nl,
3636
},
3737
{
3838
`$a$.`,
39-
`<p><code class="language-math is-loading">a</code>.</p>` + nl,
39+
`<p><code class="language-math">a</code>.</p>` + nl,
4040
},
4141
{
4242
`.$a$`,
@@ -64,27 +64,27 @@ func TestMathRender(t *testing.T) {
6464
},
6565
{
6666
"$a$ ($b$) [$c$] {$d$}",
67-
`<p><code class="language-math is-loading">a</code> (<code class="language-math is-loading">b</code>) [$c$] {$d$}</p>` + nl,
67+
`<p><code class="language-math">a</code> (<code class="language-math">b</code>) [$c$] {$d$}</p>` + nl,
6868
},
6969
{
7070
"$$a$$",
71-
`<code class="chroma language-math display">a</code>` + nl,
71+
`<code class="language-math display">a</code>` + nl,
7272
},
7373
{
7474
"$$a$$ test",
75-
`<p><code class="language-math display is-loading">a</code> test</p>` + nl,
75+
`<p><code class="language-math">a</code> test</p>` + nl,
7676
},
7777
{
7878
"test $$a$$",
79-
`<p>test <code class="language-math display is-loading">a</code></p>` + nl,
79+
`<p>test <code class="language-math">a</code></p>` + nl,
8080
},
8181
{
8282
`foo $x=\$$ bar`,
83-
`<p>foo <code class="language-math is-loading">x=\$</code> bar</p>` + nl,
83+
`<p>foo <code class="language-math">x=\$</code> bar</p>` + nl,
8484
},
8585
{
8686
`$\text{$b$}$`,
87-
`<p><code class="language-math is-loading">\text{$b$}</code></p>` + nl,
87+
`<p><code class="language-math">\text{$b$}</code></p>` + nl,
8888
},
8989
}
9090

@@ -110,7 +110,7 @@ func TestMathRenderBlockIndent(t *testing.T) {
110110
\alpha
111111
\]
112112
`,
113-
`<pre class="code-block is-loading"><code class="chroma language-math display">
113+
`<pre class="code-block is-loading"><code class="language-math display">
114114
\alpha
115115
</code></pre>
116116
`,
@@ -122,7 +122,7 @@ func TestMathRenderBlockIndent(t *testing.T) {
122122
\alpha
123123
\]
124124
`,
125-
`<pre class="code-block is-loading"><code class="chroma language-math display">
125+
`<pre class="code-block is-loading"><code class="language-math display">
126126
\alpha
127127
</code></pre>
128128
`,
@@ -137,7 +137,7 @@ a
137137
d
138138
\]
139139
`,
140-
`<pre class="code-block is-loading"><code class="chroma language-math display">
140+
`<pre class="code-block is-loading"><code class="language-math display">
141141
a
142142
b
143143
c
@@ -154,7 +154,7 @@ c
154154
c
155155
\]
156156
`,
157-
`<pre class="code-block is-loading"><code class="chroma language-math display">
157+
`<pre class="code-block is-loading"><code class="language-math display">
158158
a
159159
b
160160
c
@@ -165,15 +165,15 @@ c
165165
"indent-0-oneline",
166166
`$$ x $$
167167
foo`,
168-
`<code class="chroma language-math display"> x </code>
168+
`<code class="language-math display"> x </code>
169169
<p>foo</p>
170170
`,
171171
},
172172
{
173173
"indent-3-oneline",
174174
` $$ x $$<SPACE>
175175
foo`,
176-
`<code class="chroma language-math display"> x </code>
176+
`<code class="language-math display"> x </code>
177177
<p>foo</p>
178178
`,
179179
},
@@ -188,10 +188,10 @@ foo`,
188188
> \]
189189
`,
190190
`<blockquote>
191-
<pre class="code-block is-loading"><code class="chroma language-math display">
191+
<pre class="code-block is-loading"><code class="language-math display">
192192
a
193193
</code></pre>
194-
<pre class="code-block is-loading"><code class="chroma language-math display">
194+
<pre class="code-block is-loading"><code class="language-math display">
195195
b
196196
</code></pre>
197197
</blockquote>
@@ -207,7 +207,7 @@ b
207207
2. b`,
208208
`<ol>
209209
<li>a
210-
<pre class="code-block is-loading"><code class="chroma language-math display">
210+
<pre class="code-block is-loading"><code class="language-math display">
211211
x
212212
</code></pre>
213213
</li>

modules/markup/markdown/math/block_renderer.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ import (
1212
"github.com/yuin/goldmark/util"
1313
)
1414

15+
// Block render output:
16+
// <pre class="code-block is-loading"><code class="language-math display">...</code></pre>
17+
//
18+
// Keep in mind that there is another "code block" render in "func (r *GlodmarkRender) highlightingRenderer"
19+
// "highlightingRenderer" outputs the math block with extra "chroma" class:
20+
// <pre class="code-block is-loading"><code class="chroma language-math display">...</code></pre>
21+
//
22+
// Special classes:
23+
// * "is-loading": show a loading indicator
24+
// * "display": used by JS to decide to render as a block, otherwise render as inline
25+
1526
// BlockRenderer represents a renderer for math Blocks
1627
type BlockRenderer struct {
1728
renderInternal *internal.RenderInternal
@@ -38,7 +49,7 @@ func (r *BlockRenderer) writeLines(w util.BufWriter, source []byte, n gast.Node)
3849
func (r *BlockRenderer) renderBlock(w util.BufWriter, source []byte, node gast.Node, entering bool) (gast.WalkStatus, error) {
3950
n := node.(*Block)
4051
if entering {
41-
code := giteaUtil.Iif(n.Inline, "", `<pre class="code-block is-loading">`) + `<code class="chroma language-math display">`
52+
code := giteaUtil.Iif(n.Inline, "", `<pre class="code-block is-loading">`) + `<code class="language-math display">`
4253
_ = r.renderInternal.FormatWithSafeAttrs(w, code)
4354
r.writeLines(w, source, n)
4455
} else {

modules/markup/markdown/math/inline_renderer.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313
"github.com/yuin/goldmark/util"
1414
)
1515

16+
// Inline render output:
17+
// <code class="language-math">...</code>
18+
1619
// InlineRenderer is an inline renderer
1720
type InlineRenderer struct {
1821
renderInternal *internal.RenderInternal
@@ -25,11 +28,7 @@ func NewInlineRenderer(renderInternal *internal.RenderInternal) renderer.NodeRen
2528

2629
func (r *InlineRenderer) renderInline(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
2730
if entering {
28-
extraClass := ""
29-
if _, ok := n.(*InlineBlock); ok {
30-
extraClass = "display "
31-
}
32-
_ = r.renderInternal.FormatWithSafeAttrs(w, `<code class="language-math %sis-loading">`, extraClass)
31+
_ = r.renderInternal.FormatWithSafeAttrs(w, `<code class="language-math">`)
3332
for c := n.FirstChild(); c != nil; c = c.NextSibling() {
3433
segment := c.(*ast.Text).Segment
3534
value := util.EscapeHTML(segment.Value(source))

templates/repo/view_list.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{/* use grid layout, still use the old ID because there are many other CSS styles depending on this ID */}}
22
<div id="repo-files-table" {{if .HasFilesWithoutLatestCommit}}hx-indicator="#repo-files-table .repo-file-cell.message" hx-trigger="load" hx-swap="morph" hx-post="{{.LastCommitLoaderURL}}"{{end}}>
3-
<div class="repo-file-line">
3+
<div class="repo-file-line repo-file-last-commit">
44
<div class="latest-commit">{{template "repo/latest_commit" .}}</div>
55
<div>{{if and .LatestCommit .LatestCommit.Committer}}{{DateUtils.TimeSince .LatestCommit.Committer.When}}{{end}}</div>
66
</div>

web_src/css/repo/clone.css

+3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
/* only used by "repo/empty.tmpl" */
22
.clone-buttons-combo {
3+
display: flex;
4+
align-items: center;
35
flex: 1;
46
}
57

68
.clone-buttons-combo input {
79
border-left: none !important;
810
border-radius: 0 !important;
11+
height: 30px;
912
}
1013

1114
/* used by the clone-panel popup */

web_src/css/repo/home-file-list.css

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
padding: 6px 10px;
4545
}
4646

47+
#repo-files-table .repo-file-last-commit {
48+
background: var(--color-box-header);
49+
}
50+
4751
#repo-files-table .repo-file-cell.name {
4852
max-width: 300px;
4953
white-space: nowrap;
@@ -59,6 +63,7 @@
5963
}
6064

6165
#repo-files-table .repo-file-cell.age {
66+
text-align: right;
6267
white-space: nowrap;
6368
color: var(--color-text-light-1);
6469
}

web_src/js/markup/math.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import {displayError} from './common.ts';
22

33
function targetElement(el: Element) {
4-
// The target element is either the current element if it has the
5-
// `is-loading` class or the pre that contains it
6-
return el.classList.contains('is-loading') ? el : el.closest('pre');
4+
// The target element is either the parent "code block with loading indicator", or itself
5+
return el.closest('.code-block.is-loading') ?? el;
76
}
87

98
export async function renderMath(): Promise<void> {

0 commit comments

Comments
 (0)