MCPcopy Create free account
hub / github.com/Feather-2/Burner-X / processCustomSyntax

Function processCustomSyntax

js/processing/markdown_processor_enhanced.js:119–170  ·  view source on GitHub ↗

* Process custom syntax (subscripts, superscripts) with enhanced robustness * @param {string} md - Markdown text * @returns {string} Processed markdown

(md)

Source from the content-addressed store, hash-verified

117 * @returns {string} Processed markdown
118 */
119 function processCustomSyntax(md) {
120 // Enhanced regex patterns with better boundary detection
121 const patterns = [
122 // Base with superscript: ${base}^{sup}$
123 {
124 regex: /\$\{\s*([^}]*?)\s*\}\^\{([^}]*?)\}\$/g,
125 replacement: (_, base, sup) => {
126 const cleanBase = (base || '').trim();
127 const cleanSup = (sup || '').trim();
128 return cleanBase ?
129 `<span>${escapeHtml(cleanBase)}<sup>${escapeHtml(cleanSup)}</sup></span>` :
130 `<sup>${escapeHtml(cleanSup)}</sup>`;
131 }
132 },
133 // Base with subscript: ${base}_{sub}$
134 {
135 regex: /\$\{\s*([^}]*?)\s*\}_\{([^}]*?)\}\$/g,
136 replacement: (_, base, sub) => {
137 const cleanBase = (base || '').trim();
138 const cleanSub = (sub || '').trim();
139 return cleanBase ?
140 `<span>${escapeHtml(cleanBase)}<sub>${escapeHtml(cleanSub)}</sub></span>` :
141 `<sub>${escapeHtml(cleanSub)}</sub>`;
142 }
143 },
144 // Empty base superscript: ${}^{sup}$
145 {
146 regex: /\$\{\s*\}\^\{([^}]*?)\}\$/g,
147 replacement: (_, sup) => `<sup>${escapeHtml((sup || '').trim())}</sup>`
148 },
149 // Empty base subscript: ${}_{sub}$
150 {
151 regex: /\$\{\s*\}_\{([^}]*?)\}\$/g,
152 replacement: (_, sub) => `<sub>${escapeHtml((sub || '').trim())}</sub>`
153 },
154 // Simple superscript: ${content}$
155 {
156 regex: /\$\{\s*([^}]*?)\s*\}\$/g,
157 replacement: (_, content) => `<sup>${escapeHtml((content || '').trim())}</sup>`
158 }
159 ];
160
161 patterns.forEach(({ regex, replacement }) => {
162 try {
163 md = md.replace(regex, replacement);
164 } catch (error) {
165 console.warn(`[MarkdownProcessorEnhanced] Custom syntax processing error:`, error);
166 }
167 });
168
169 return md;
170 }
171
172 /**
173 * Enhanced KaTeX rendering with improved error handling and formula analysis

Callers 1

safeMarkdownEnhancedFunction · 0.85

Calls 1

escapeHtmlFunction · 0.70

Tested by

no test coverage detected