@@ -55,10 +55,16 @@ def __init__(self, *args, **kwargs):
5555 'add_preview' : [False , 'Add a preview node before each math node' ],
5656 'use_asciimath' :
5757 [False , 'Use AsciiMath syntax instead of TeX syntax' ],
58+ 'use_gitlab_delimiters' :
59+ [False , 'Use GitLab-style $`...`$ delimiters' ],
5860 }
5961 super (MathExtension , self ).__init__ (* args , ** kwargs )
6062
6163 def extendMarkdown (self , md ):
64+ add_preview = self .getConfig ('add_preview' )
65+ use_asciimath = self .getConfig ('use_asciimath' )
66+ use_gitlab_delimiters = self .getConfig ('use_gitlab_delimiters' )
67+
6268 inlinemathpatterns = (
6369 InlineMathPattern (r'(?<!\\|\$)(\$)([^\$]+)(\$)' ), # $...$
6470 InlineMathPattern (r'(?<!\\)(\\\()(.+?)(\\\))' ) # \(...\)
@@ -71,11 +77,14 @@ def extendMarkdown(self, md):
7177 )
7278 if not self .getConfig ('enable_dollar_delimiter' ):
7379 inlinemathpatterns = inlinemathpatterns [1 :]
74- if self . getConfig ( ' use_asciimath' ) :
80+ if use_asciimath :
7581 mathpatterns = mathpatterns [:- 1 ] # \begin...\end is TeX only
82+ if use_gitlab_delimiters :
83+ # https://gitlab.com/gitlab-org/gitlab/blob/master/doc/user/markdown.md#math
84+ inlinemathpatterns = (
85+ InlineMathPattern (r'(?<!\\)(\$`)([^`]+)(`\$)' ), # $`...`$
86+ )
7687
77- add_preview = self .getConfig ('add_preview' )
78- use_asciimath = self .getConfig ('use_asciimath' )
7988 content_type = 'math/asciimath' if use_asciimath else 'math/tex'
8089 for i , pattern in enumerate (mathpatterns ):
8190 pattern ._add_preview = add_preview
@@ -85,7 +94,10 @@ def extendMarkdown(self, md):
8594 for i , pattern in enumerate (inlinemathpatterns ):
8695 pattern ._add_preview = add_preview
8796 pattern ._content_type = content_type
88- md .inlinePatterns .register (pattern , 'math-inline-%d' % i , 185 )
97+ # to use gitlab delimiters, we should have higher priority than
98+ # 'backtick' which has 190
99+ priority = 195 if use_gitlab_delimiters else 185
100+ md .inlinePatterns .register (pattern , 'math-inline-%d' % i , priority )
89101 if self .getConfig ('enable_dollar_delimiter' ):
90102 md .ESCAPED_CHARS .append ('$' )
91103
0 commit comments