mirror of
https://github.com/go-gitea/gitea
synced 2025-07-04 01:27:20 +00:00
Fix markdown render behaviors (#34122)
* Fix #27645 * Add config options `MATH_CODE_BLOCK_DETECTION`, problematic syntaxes are disabled by default * Fix #33639 * Add config options `RENDER_OPTIONS_*`, old behaviors are kept
This commit is contained in:
@ -14,10 +14,11 @@ import (
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
Enabled bool
|
||||
ParseDollarInline bool
|
||||
ParseDollarBlock bool
|
||||
ParseSquareBlock bool
|
||||
Enabled bool
|
||||
ParseInlineDollar bool // inline $$ xxx $$ text
|
||||
ParseInlineParentheses bool // inline \( xxx \) text
|
||||
ParseBlockDollar bool // block $$ multiple-line $$ text
|
||||
ParseBlockSquareBrackets bool // block \[ multiple-line \] text
|
||||
}
|
||||
|
||||
// Extension is a math extension
|
||||
@ -42,16 +43,16 @@ func (e *Extension) Extend(m goldmark.Markdown) {
|
||||
return
|
||||
}
|
||||
|
||||
inlines := []util.PrioritizedValue{util.Prioritized(NewInlineBracketParser(), 501)}
|
||||
if e.options.ParseDollarInline {
|
||||
inlines = append(inlines, util.Prioritized(NewInlineDollarParser(), 502))
|
||||
var inlines []util.PrioritizedValue
|
||||
if e.options.ParseInlineParentheses {
|
||||
inlines = append(inlines, util.Prioritized(NewInlineParenthesesParser(), 501))
|
||||
}
|
||||
inlines = append(inlines, util.Prioritized(NewInlineDollarParser(e.options.ParseInlineDollar), 502))
|
||||
|
||||
m.Parser().AddOptions(parser.WithInlineParsers(inlines...))
|
||||
|
||||
m.Parser().AddOptions(parser.WithBlockParsers(
|
||||
util.Prioritized(NewBlockParser(e.options.ParseDollarBlock, e.options.ParseSquareBlock), 701),
|
||||
util.Prioritized(NewBlockParser(e.options.ParseBlockDollar, e.options.ParseBlockSquareBrackets), 701),
|
||||
))
|
||||
|
||||
m.Renderer().AddOptions(renderer.WithNodeRenderers(
|
||||
util.Prioritized(NewBlockRenderer(e.renderInternal), 501),
|
||||
util.Prioritized(NewInlineRenderer(e.renderInternal), 502),
|
||||
|
Reference in New Issue
Block a user