@@ -39,61 +39,6 @@ function escapeLatexDelimiters(text: string) {
39
39
. replace ( '\\]/g' , '\\\\]' ) ;
40
40
}
41
41
42
- /**
43
- * Type predicate function that determines whether a given DOM Node is a Text
44
- * node.
45
- */
46
- function isTextNode ( node : Node | null ) : node is Text {
47
- return node ?. nodeType === Node . TEXT_NODE ;
48
- }
49
-
50
- /**
51
- * Escapes all `$` symbols present in an HTML element except those within the
52
- * following elements: `pre`, `code`, `samp`, `kbd`.
53
- *
54
- * This prevents `$` symbols from being used as inline math delimiters, allowing
55
- * `$` symbols to be used literally to denote quantities of USD. This does not
56
- * escape literal `$` within elements that display their contents literally,
57
- * like code elements. This overrides JupyterLab's default rendering of MarkDown
58
- * w/ LaTeX.
59
- *
60
- * The Jupyter AI system prompt should explicitly request that the LLM not use
61
- * `$` as an inline math delimiter. This is the default behavior.
62
- */
63
- function escapeDollarSymbols ( el : HTMLElement ) {
64
- // Get all text nodes that are not within pre, code, samp, or kbd elements
65
- const walker = document . createTreeWalker ( el , NodeFilter . SHOW_TEXT , {
66
- acceptNode : node => {
67
- const isInSkippedElements = node . parentElement ?. closest (
68
- 'pre, code, samp, kbd'
69
- ) ;
70
- return isInSkippedElements
71
- ? NodeFilter . FILTER_SKIP
72
- : NodeFilter . FILTER_ACCEPT ;
73
- }
74
- } ) ;
75
-
76
- // Collect all valid text nodes in an array.
77
- const textNodes : Text [ ] = [ ] ;
78
- let currentNode : Node | null ;
79
- while ( ( currentNode = walker . nextNode ( ) ) ) {
80
- if ( isTextNode ( currentNode ) ) {
81
- textNodes . push ( currentNode ) ;
82
- }
83
- }
84
-
85
- // Replace each `$` symbol with `\$` for each text node, unless there is
86
- // another `$` symbol adjacent or it is already escaped. Examples:
87
- // - `$10 - $5` => `\$10 - \$5` (escaped)
88
- // - `$$ \infty $$` => `$$ \infty $$` (unchanged)
89
- // - `\$10` => `\$10` (unchanged, already escaped)
90
- textNodes . forEach ( node => {
91
- if ( node . textContent ) {
92
- node . textContent = node . textContent . replace ( / (?< ! [ $ \\ ] ) \$ (? ! \$ ) / g, '\\$' ) ;
93
- }
94
- } ) ;
95
- }
96
-
97
42
function RendermimeMarkdownBase ( props : RendermimeMarkdownProps ) : JSX . Element {
98
43
const appendContent = props . appendContent || false ;
99
44
const [ renderedContent , setRenderedContent ] = useState < HTMLElement | null > (
@@ -124,8 +69,7 @@ function RendermimeMarkdownBase(props: RendermimeMarkdownProps): JSX.Element {
124
69
) ;
125
70
}
126
71
127
- // step 2: render LaTeX via MathJax, while escaping single dollar symbols.
128
- escapeDollarSymbols ( renderer . node ) ;
72
+ // step 2: render LaTeX via MathJax.
129
73
props . rmRegistry . latexTypesetter ?. typeset ( renderer . node ) ;
130
74
131
75
const newCodeToolbarDefns : [ HTMLDivElement , CodeToolbarProps ] [ ] = [ ] ;
0 commit comments