Skip to content

Commit e7bf5f1

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Tweak katex options (go-gitea#21828) Ignore issue template with a special name (go-gitea#21830)
2 parents 3581704 + c144942 commit e7bf5f1

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

modules/structs/issue.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
package structs
66

77
import (
8-
"path/filepath"
8+
"path"
99
"time"
1010
)
1111

@@ -163,11 +163,11 @@ const (
163163

164164
// Type returns the type of IssueTemplate, can be "md", "yaml" or empty for known
165165
func (it IssueTemplate) Type() IssueTemplateType {
166-
if it.Name == "config.yaml" || it.Name == "config.yml" {
166+
if base := path.Base(it.FileName); base == "config.yaml" || base == "config.yml" {
167167
// ignore config.yaml which is a special configuration file
168168
return ""
169169
}
170-
if ext := filepath.Ext(it.FileName); ext == ".md" {
170+
if ext := path.Ext(it.FileName); ext == ".md" {
171171
return IssueTemplateTypeMarkdown
172172
} else if ext == ".yaml" || ext == ".yml" {
173173
return IssueTemplateTypeYaml

modules/structs/issue_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package structs
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestIssueTemplate_Type(t *testing.T) {
14+
tests := []struct {
15+
fileName string
16+
want IssueTemplateType
17+
}{
18+
{
19+
fileName: ".gitea/ISSUE_TEMPLATE/bug_report.yaml",
20+
want: IssueTemplateTypeYaml,
21+
},
22+
{
23+
fileName: ".gitea/ISSUE_TEMPLATE/bug_report.md",
24+
want: IssueTemplateTypeMarkdown,
25+
},
26+
{
27+
fileName: ".gitea/ISSUE_TEMPLATE/bug_report.txt",
28+
want: "",
29+
},
30+
{
31+
fileName: ".gitea/ISSUE_TEMPLATE/config.yaml",
32+
want: "",
33+
},
34+
}
35+
for _, tt := range tests {
36+
t.Run(tt.fileName, func(t *testing.T) {
37+
it := IssueTemplate{
38+
FileName: tt.fileName,
39+
}
40+
assert.Equal(t, tt.want, it.Type())
41+
})
42+
}
43+
}

web_src/js/markup/math.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ export async function renderMath() {
2323

2424
for (const el of els) {
2525
const source = el.textContent;
26-
const options = {display: el.classList.contains('display')};
26+
const nodeName = el.classList.contains('display') ? 'p' : 'span';
2727

2828
try {
29-
const markup = katex.renderToString(source, options);
30-
const tempEl = document.createElement(options.display ? 'p' : 'span');
31-
tempEl.innerHTML = markup;
29+
const tempEl = document.createElement(nodeName);
30+
katex.render(source, tempEl, {
31+
maxSize: 25,
32+
maxExpand: 50,
33+
});
3234
targetElement(el).replaceWith(tempEl);
3335
} catch (error) {
3436
displayError(el, error);

0 commit comments

Comments
 (0)