@@ -14,6 +14,7 @@ import (
1414 "code.gitea.io/gitea/modules/markup/markdown"
1515 "code.gitea.io/gitea/modules/setting"
1616 api "code.gitea.io/gitea/modules/structs"
17+ "code.gitea.io/gitea/modules/util"
1718
1819 "gopkg.in/yaml.v2"
1920)
@@ -95,14 +96,27 @@ func unmarshal(filename string, content []byte) (*api.IssueTemplate, error) {
9596 }{}
9697
9798 if typ := it .Type (); typ == api .IssueTemplateTypeMarkdown {
98- templateBody , err := markdown .ExtractMetadata (string (content ), it )
99- if err != nil {
100- return nil , err
101- }
102- it .Content = templateBody
103- if it .About == "" {
104- if _ , err := markdown .ExtractMetadata (string (content ), compatibleTemplate ); err == nil && compatibleTemplate .About != "" {
105- it .About = compatibleTemplate .About
99+ if templateBody , err := markdown .ExtractMetadata (string (content ), it ); err != nil {
100+ // The only thing we know here is that we can't extract metadata from the content,
101+ // it's hard to tell if metadata doesn't exist or metadata isn't valid.
102+ // There's an example template:
103+ //
104+ // ---
105+ // # Title
106+ // ---
107+ // Content
108+ //
109+ // It could be a valid markdown with two horizontal lines, or an invalid markdown with wrong metadata.
110+
111+ it .Content = string (content )
112+ it .Name = filepath .Base (it .FileName )
113+ it .About , _ = util .SplitStringAtByteN (it .Content , 80 )
114+ } else {
115+ it .Content = templateBody
116+ if it .About == "" {
117+ if _ , err := markdown .ExtractMetadata (string (content ), compatibleTemplate ); err == nil && compatibleTemplate .About != "" {
118+ it .About = compatibleTemplate .About
119+ }
106120 }
107121 }
108122 } else if typ == api .IssueTemplateTypeYaml {
0 commit comments