Skip to content

Commit 6112dc8

Browse files
committed
fix default (non-conflict) inline syntax
1 parent 80ebb6f commit 6112dc8

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

modules/markup/markdown/markdown_math_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ func TestMathRenderOptions(t *testing.T) {
257257
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(res)), "input: %s", input)
258258
}
259259

260+
// default (non-conflict) inline syntax
261+
test(t, `<p><code class="language-math">a</code></p>`, "$`a`$")
262+
260263
// ParseInlineDollar
261264
test(t, `<p>$a$</p>`, `$a$`)
262265
setting.Markdown.MathCodeBlockOptions.ParseInlineDollar = true

modules/markup/markdown/math/inline_parser.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ type inlineParser struct {
1616
endBytesSingleDollar []byte
1717
endBytesDoubleDollar []byte
1818
endBytesParentheses []byte
19+
enableInlineDollar bool
1920
}
2021

21-
var defaultInlineDollarParser = &inlineParser{
22-
trigger: []byte{'$'},
23-
endBytesSingleDollar: []byte{'$'},
24-
endBytesDoubleDollar: []byte{'$', '$'},
25-
}
26-
27-
func NewInlineDollarParser() parser.InlineParser {
28-
return defaultInlineDollarParser
22+
func NewInlineDollarParser(enableInlineDollar bool) parser.InlineParser {
23+
return &inlineParser{
24+
trigger: []byte{'$'},
25+
endBytesSingleDollar: []byte{'$'},
26+
endBytesDoubleDollar: []byte{'$', '$'},
27+
enableInlineDollar: enableInlineDollar,
28+
}
2929
}
3030

3131
var defaultInlineParenthesesParser = &inlineParser{
@@ -89,6 +89,10 @@ func (parser *inlineParser) Parse(parent ast.Node, block text.Reader, pc parser.
8989
stopMark = parser.endBytesParentheses
9090
}
9191

92+
if line[0] == '$' && !parser.enableInlineDollar && (len(line) == 1 || line[1] != '`') {
93+
return nil
94+
}
95+
9296
if checkSurrounding {
9397
precedingCharacter := block.PrecendingCharacter()
9498
if precedingCharacter < 256 && (isAlphanumeric(byte(precedingCharacter)) || isPunctuation(byte(precedingCharacter))) {

modules/markup/markdown/math/math.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ func (e *Extension) Extend(m goldmark.Markdown) {
4747
if e.options.ParseInlineParentheses {
4848
inlines = append(inlines, util.Prioritized(NewInlineParenthesesParser(), 501))
4949
}
50-
if e.options.ParseInlineDollar {
51-
inlines = append(inlines, util.Prioritized(NewInlineDollarParser(), 502))
52-
}
50+
inlines = append(inlines, util.Prioritized(NewInlineDollarParser(e.options.ParseInlineDollar), 502))
51+
5352
m.Parser().AddOptions(parser.WithInlineParsers(inlines...))
5453
m.Parser().AddOptions(parser.WithBlockParsers(
5554
util.Prioritized(NewBlockParser(e.options.ParseBlockDollar, e.options.ParseBlockSquareBrackets), 701),

0 commit comments

Comments
 (0)