Ship CSRF-drift + markdown fixes to production #25
+15
-3
@@ -41,10 +41,22 @@ function parseMarkdown(markdown) {
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
|
||||
// Code blocks (```code```) - preserve content and don't process further
|
||||
// Code blocks (```lang\ncode\n```) - preserve content and don't process further
|
||||
const codeBlocks = [];
|
||||
html = html.replace(/```([\s\S]*?)```/g, function(match, code) {
|
||||
codeBlocks.push('<pre class="code-block"><code>' + code + '</code></pre>');
|
||||
html = html.replace(/```([a-zA-Z0-9_+-]*)\n?([\s\S]*?)```/g, function(match, lang, code) {
|
||||
lang = lang ? lang.trim() : '';
|
||||
const displayLang = lang || 'text';
|
||||
|
||||
// Build header with optional copy button if one exists in your UI, otherwise just lang
|
||||
const header = '<div class="lt-code-header"><span class="lt-code-lang">' + displayLang + '</span></div>';
|
||||
|
||||
// Remove exactly one trailing newline from code block if it exists
|
||||
if (code.endsWith('\n')) {
|
||||
code = code.slice(0, -1);
|
||||
}
|
||||
|
||||
// Wrap in the specific UI classes expected by base.css
|
||||
codeBlocks.push('<div class="lt-code-block">' + header + '<pre><code>' + code + '</code></pre></div>');
|
||||
return '%%CODEBLOCK' + (codeBlocks.length - 1) + '%%';
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user