From 92dd24716d22bbb849365605a13b94e8897d06fd Mon Sep 17 00:00:00 2001 From: Jason Song Date: Wed, 16 Nov 2022 19:14:58 +0800 Subject: [PATCH 1/2] Ignore issue template with a special name (#21830) A file in `ISSUE_TEMPLATE` with the name `config.yml` shouldn't be treated as a YAML template, it's for [configuring the template chooser](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository#configuring-the-template-chooser). The old code tried to ignore the file, but it didn't work, caused by #20987. That's why the warning is displayed: image Note that this PR is not an implementation of `config.yml`, there will be another one to do it. --- modules/structs/issue.go | 6 ++--- modules/structs/issue_test.go | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 modules/structs/issue_test.go diff --git a/modules/structs/issue.go b/modules/structs/issue.go index 70f5e1ba8eaa..25c6251fbf2d 100644 --- a/modules/structs/issue.go +++ b/modules/structs/issue.go @@ -5,7 +5,7 @@ package structs import ( - "path/filepath" + "path" "time" ) @@ -163,11 +163,11 @@ const ( // Type returns the type of IssueTemplate, can be "md", "yaml" or empty for known func (it IssueTemplate) Type() IssueTemplateType { - if it.Name == "config.yaml" || it.Name == "config.yml" { + if base := path.Base(it.FileName); base == "config.yaml" || base == "config.yml" { // ignore config.yaml which is a special configuration file return "" } - if ext := filepath.Ext(it.FileName); ext == ".md" { + if ext := path.Ext(it.FileName); ext == ".md" { return IssueTemplateTypeMarkdown } else if ext == ".yaml" || ext == ".yml" { return IssueTemplateTypeYaml diff --git a/modules/structs/issue_test.go b/modules/structs/issue_test.go new file mode 100644 index 000000000000..5312585d0f0f --- /dev/null +++ b/modules/structs/issue_test.go @@ -0,0 +1,43 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package structs + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestIssueTemplate_Type(t *testing.T) { + tests := []struct { + fileName string + want IssueTemplateType + }{ + { + fileName: ".gitea/ISSUE_TEMPLATE/bug_report.yaml", + want: IssueTemplateTypeYaml, + }, + { + fileName: ".gitea/ISSUE_TEMPLATE/bug_report.md", + want: IssueTemplateTypeMarkdown, + }, + { + fileName: ".gitea/ISSUE_TEMPLATE/bug_report.txt", + want: "", + }, + { + fileName: ".gitea/ISSUE_TEMPLATE/config.yaml", + want: "", + }, + } + for _, tt := range tests { + t.Run(tt.fileName, func(t *testing.T) { + it := IssueTemplate{ + FileName: tt.fileName, + } + assert.Equal(t, tt.want, it.Type()) + }) + } +} From c144942b23eb6e05a60526cc6d2b88b488ca75dd Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 17 Nov 2022 02:04:09 +0100 Subject: [PATCH 2/2] Tweak katex options (#21828) - Render directly into DOM, skipping string conversion - Add limiting options to prevent excessive size/macros - Remove invalid `display` option previously passed Ref: https://katex.org/docs/options.html Co-authored-by: John Olheiser --- web_src/js/markup/math.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/web_src/js/markup/math.js b/web_src/js/markup/math.js index 5790a327a51f..d4e40d5be2e3 100644 --- a/web_src/js/markup/math.js +++ b/web_src/js/markup/math.js @@ -23,12 +23,14 @@ export async function renderMath() { for (const el of els) { const source = el.textContent; - const options = {display: el.classList.contains('display')}; + const nodeName = el.classList.contains('display') ? 'p' : 'span'; try { - const markup = katex.renderToString(source, options); - const tempEl = document.createElement(options.display ? 'p' : 'span'); - tempEl.innerHTML = markup; + const tempEl = document.createElement(nodeName); + katex.render(source, tempEl, { + maxSize: 25, + maxExpand: 50, + }); targetElement(el).replaceWith(tempEl); } catch (error) { displayError(el, error);