88 "strings"
99
1010 "code.gitea.io/gitea/modules/log"
11+ "code.gitea.io/gitea/modules/util"
1112)
1213
1314// ExternalMarkupRenderers represents the external markup renderers
@@ -23,6 +24,11 @@ const (
2324 RenderContentModeIframe = "iframe"
2425)
2526
27+ type MarkdownRenderOptions struct {
28+ NewLineHardBreak bool
29+ ShortIssuePattern bool // Actually it is a "markup" option because it is used in "post processor"
30+ }
31+
2632type MarkdownMathCodeBlockOptions struct {
2733 ParseInlineDollar bool
2834 ParseInlineParentheses bool
@@ -32,18 +38,19 @@ type MarkdownMathCodeBlockOptions struct {
3238
3339// Markdown settings
3440var Markdown = struct {
35- EnableHardLineBreakInComments bool
36- EnableHardLineBreakInDocuments bool
37- CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"`
38- FileExtensions []string
39- EnableMath bool
40- MathCodeBlockDetection []string
41- MathCodeBlockOptions MarkdownMathCodeBlockOptions `ini:"-"`
41+ RenderOptionsComment MarkdownRenderOptions `ini:"-"`
42+ RenderOptionsWiki MarkdownRenderOptions `ini:"-"`
43+ RenderOptionsRepoFile MarkdownRenderOptions `ini:"-"`
44+
45+ CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"` // Actually it is a "markup" option because it is used in "post processor"
46+ FileExtensions []string
47+
48+ EnableMath bool
49+ MathCodeBlockDetection []string
50+ MathCodeBlockOptions MarkdownMathCodeBlockOptions `ini:"-"`
4251}{
43- EnableHardLineBreakInComments : true ,
44- EnableHardLineBreakInDocuments : false ,
45- FileExtensions : strings .Split (".md,.markdown,.mdown,.mkd,.livemd" , "," ),
46- EnableMath : true ,
52+ FileExtensions : strings .Split (".md,.markdown,.mdown,.mkd,.livemd" , "," ),
53+ EnableMath : true ,
4754}
4855
4956// MarkupRenderer defines the external parser configured in ini
@@ -69,15 +76,38 @@ type MarkupSanitizerRule struct {
6976
7077func loadMarkupFrom (rootCfg ConfigProvider ) {
7178 mustMapSetting (rootCfg , "markdown" , & Markdown )
79+ const none = "none"
80+
81+ const renderOptionShortIssuePattern = "short-issue-pattern"
82+ const renderOptionNewLineHardBreak = "new-line-hard-break"
83+ cfgMarkdown := rootCfg .Section ("markdown" )
84+ parseMarkdownRenderOptions := func (key string , defaults []string ) (ret MarkdownRenderOptions ) {
85+ options := cfgMarkdown .Key (key ).Strings ("," )
86+ options = util .IfEmpty (options , defaults )
87+ for _ , opt := range options {
88+ switch opt {
89+ case renderOptionShortIssuePattern :
90+ ret .ShortIssuePattern = true
91+ case renderOptionNewLineHardBreak :
92+ ret .NewLineHardBreak = true
93+ case none :
94+ ret = MarkdownRenderOptions {}
95+ case "" :
96+ default :
97+ log .Error ("Unknown markdown render option in %s: %s" , key , opt )
98+ }
99+ }
100+ return ret
101+ }
102+ Markdown .RenderOptionsComment = parseMarkdownRenderOptions ("RENDER_OPTIONS_COMMENT" , []string {renderOptionShortIssuePattern , renderOptionNewLineHardBreak })
103+ Markdown .RenderOptionsWiki = parseMarkdownRenderOptions ("RENDER_OPTIONS_WIKI" , []string {renderOptionShortIssuePattern })
104+ Markdown .RenderOptionsRepoFile = parseMarkdownRenderOptions ("RENDER_OPTIONS_REPO_FILE" , nil )
72105
73- const mathCodeNone = "none"
74106 const mathCodeInlineDollar = "inline-dollar"
75107 const mathCodeInlineParentheses = "inline-parentheses"
76108 const mathCodeBlockDollar = "block-dollar"
77109 const mathCodeBlockSquareBrackets = "block-square-brackets"
78- if len (Markdown .MathCodeBlockDetection ) == 0 {
79- Markdown .MathCodeBlockDetection = []string {mathCodeInlineDollar , mathCodeBlockDollar }
80- }
110+ Markdown .MathCodeBlockDetection = util .IfEmpty (Markdown .MathCodeBlockDetection , []string {mathCodeInlineDollar , mathCodeBlockDollar })
81111 Markdown .MathCodeBlockOptions = MarkdownMathCodeBlockOptions {}
82112 for _ , s := range Markdown .MathCodeBlockDetection {
83113 switch s {
@@ -89,11 +119,11 @@ func loadMarkupFrom(rootCfg ConfigProvider) {
89119 Markdown .MathCodeBlockOptions .ParseBlockDollar = true
90120 case mathCodeBlockSquareBrackets :
91121 Markdown .MathCodeBlockOptions .ParseBlockSquareBrackets = true
92- case mathCodeNone :
122+ case none :
93123 Markdown .MathCodeBlockOptions = MarkdownMathCodeBlockOptions {}
94124 case "" :
95125 default :
96- log .Fatal ("Unknown math code block detection option: " + s )
126+ log .Error ("Unknown math code block detection option: %s" , s )
97127 }
98128 }
99129
0 commit comments