@@ -10,6 +10,7 @@ const PRECEDENCE_LEVEL_EMPHASIS = 1;
1010const PRECEDENCE_LEVEL_LINK = 10 ;
1111const PRECEDENCE_LEVEL_HTML = 100 ;
1212const PRECEDENCE_LEVEL_CODE_SPAN = 100 ;
13+ const PRECEDENCE_LEVEL_LATEX = 100 ;
1314
1415// Punctuation characters as specified in
1516// https://github.github.com/gfm/#ascii-punctuation-character
@@ -64,6 +65,11 @@ module.exports = grammar(add_inline_rules({
6465
6566 $ . _strikethrough_open ,
6667 $ . _strikethrough_close ,
68+
69+ // Opening and closing delimiters for latex. These are sequences of one or more dollar signs.
70+ // An opening token does not mean the text after has to be latex if there is no closing token
71+ $ . _latex_span_start ,
72+ $ . _latex_span_close ,
6773 ] ,
6874 precedences : $ => [
6975 // [$._strong_emphasis_star, $._inline_element_no_star],
@@ -76,6 +82,7 @@ module.exports = grammar(add_inline_rules({
7682 // More conflicts are defined in `add_inline_rules`
7783 conflicts : $ => [
7884 [ $ . code_span , $ . _inline_base ] ,
85+ [ $ . latex_block , $ . _inline_base ] ,
7986
8087 [ $ . _closing_tag , $ . _text_base ] ,
8188 [ $ . _open_tag , $ . _text_base ] ,
@@ -115,6 +122,7 @@ module.exports = grammar(add_inline_rules({
115122 //
116123 // * collections of inlines
117124 // * code spans
125+ // * latex spans
118126 // * emphasis
119127 // * textual content
120128 //
@@ -127,6 +135,12 @@ module.exports = grammar(add_inline_rules({
127135 alias ( $ . _code_span_close , $ . code_span_delimiter )
128136 ) ) ,
129137
138+ latex_block : $ => prec . dynamic ( PRECEDENCE_LEVEL_LATEX , seq (
139+ alias ( $ . _latex_span_start , $ . latex_span_delimiter ) ,
140+ repeat ( choice ( $ . _text_base , '[' , ']' , $ . _soft_line_break , $ . _html_tag ) ) ,
141+ alias ( $ . _latex_span_close , $ . latex_span_delimiter ) ,
142+ ) ) ,
143+
130144 // Different kinds of links:
131145 // * inline links (https://github.github.com/gfm/#inline-link)
132146 // * full reference links (https://github.github.com/gfm/#full-reference-link)
@@ -328,11 +342,13 @@ module.exports = grammar(add_inline_rules({
328342 $ . email_autolink ,
329343 $ . entity_reference ,
330344 $ . numeric_character_reference ,
345+ ( common . EXTENSION_LATEX ? $ . latex_block : choice ( ) ) ,
331346 $ . code_span ,
332347 alias ( $ . _html_tag , $ . html_tag ) ,
333348 $ . _text_base ,
334349 $ . _code_span_start ,
335350 common . EXTENSION_TAGS ? $ . tag : choice ( ) ,
351+ ( common . EXTENSION_LATEX ? $ . _latex_span_start : choice ( ) ) ,
336352 ) ) ) ,
337353 _text_base : $ => choice (
338354 $ . _word ,
@@ -346,6 +362,7 @@ module.exports = grammar(add_inline_rules({
346362 _text_inline_no_link : $ => choice (
347363 $ . _text_base ,
348364 $ . _code_span_start ,
365+ $ . _latex_span_start ,
349366 $ . _emphasis_open_star ,
350367 $ . _emphasis_open_underscore ,
351368 ) ,
0 commit comments