Lashtw commited on
Commit
077ad81
·
verified ·
1 Parent(s): 6cacd7b

Upload 9 files

Browse files
Files changed (1) hide show
  1. src/views/InstructorView.js +11 -4
src/views/InstructorView.js CHANGED
@@ -342,7 +342,11 @@ export function setupInstructorEvents() {
342
  function cleanText(str, isCode = false) {
343
  if (!str) return '';
344
 
345
- // 1. Normalize line endings
 
 
 
 
346
  str = str.replace(/\r\n/g, '\n');
347
 
348
  if (isCode) {
@@ -355,8 +359,11 @@ export function setupInstructorEvents() {
355
 
356
  let minIndent = null;
357
  for (const line of lines) {
358
- if (line.trim().length === 0) continue;
359
- const currentIndent = line.match(/^\s*/)[0].length;
 
 
 
360
  if (minIndent === null || currentIndent < minIndent) {
361
  minIndent = currentIndent;
362
  }
@@ -369,7 +376,7 @@ export function setupInstructorEvents() {
369
  } else {
370
  // Aggressive Flatten for Text Prompts (Force Left Align)
371
  return str.split('\n')
372
- .map(line => line.trimStart()) // Remove ALL leading space from every line
373
  .filter((line, index, arr) => {
374
  // Remove leading/trailing empty lines
375
  if (line.trim() === '' && (index === 0 || index === arr.length - 1)) return false;
 
342
  function cleanText(str, isCode = false) {
343
  if (!str) return '';
344
 
345
+ // 1. Convert HTML entities if present (common in innerHTML injection flows)
346
+ str = str.replace(/&nbsp;/g, ' ');
347
+ str = str.replace(/<br\s*\/?>/gi, '\n');
348
+
349
+ // 2. Normalize line endings
350
  str = str.replace(/\r\n/g, '\n');
351
 
352
  if (isCode) {
 
359
 
360
  let minIndent = null;
361
  for (const line of lines) {
362
+ // Determine indent level
363
+ const content = line.replace(/^[\s\u3000\u00A0]+/, '');
364
+ if (content.length === 0) continue; // Skip empty/whitespace-only lines
365
+
366
+ const currentIndent = line.length - content.length;
367
  if (minIndent === null || currentIndent < minIndent) {
368
  minIndent = currentIndent;
369
  }
 
376
  } else {
377
  // Aggressive Flatten for Text Prompts (Force Left Align)
378
  return str.split('\n')
379
+ .map(line => line.replace(/^[\s\u3000\u00A0]+/g, '')) // Regex remove ALL leading whitespace (Space, Tab, FullWidth, NBSP)
380
  .filter((line, index, arr) => {
381
  // Remove leading/trailing empty lines
382
  if (line.trim() === '' && (index === 0 || index === arr.length - 1)) return false;