Skip to content

Commit ba7301b

Browse files
committed
fix: improve activity feed compatibility for visual diffs
- Remove HTML tags (<ins>, <del>) from diff output for activity feed compatibility - Add callout block emoji transitions (e.g., ℹ️→🔴 for ::: info → ::: error) - Use plain text with arrows (→) to show changes instead of HTML formatting The activity feed doesn't support HTML tags properly, causing them to appear as escaped text. This change uses plain text formatting that displays correctly. Signed-off-by: Alexander Askin <[email protected]>
1 parent 28766b1 commit ba7301b

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

lib/Service/DiffService.php

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ private function enhanceWithWordLevelDiff(array $operations, array $oldLines, ar
344344
if (!empty(trim($line))) {
345345
$formatted = $this->formatSpecialLine($line);
346346
if ($formatted !== null) {
347-
$lines[] = '' . $newLineNumber . ' <ins>' . $formatted . '</ins>';
347+
$lines[] = '' . $newLineNumber . ' ' . $formatted;
348348
}
349349
}
350350
break;
@@ -355,8 +355,7 @@ private function enhanceWithWordLevelDiff(array $operations, array $oldLines, ar
355355
if (!empty(trim($line))) {
356356
$formatted = $this->formatSpecialLine($line);
357357
if ($formatted !== null) {
358-
// Show old line number with strikethrough to indicate it's from old version
359-
$lines[] = '🗑️<del>' . $oldLineNumber . '</del> <del>' . $formatted . '</del>';
358+
$lines[] = '🗑️' . $oldLineNumber . ' ' . $formatted;
360359
}
361360
}
362361
break;
@@ -421,14 +420,19 @@ private function generateWordLevelDiff(string $oldLine, string $newLine): string
421420
if ($this->isCheckboxChange($oldLine, $newLine)) {
422421
return $this->generateCheckboxDiff($oldLine, $newLine);
423422
}
424-
423+
424+
// Check if this is a callout block type change
425+
if ($this->isCalloutBlockChange($oldLine, $newLine)) {
426+
return $this->generateCalloutBlockDiff($oldLine, $newLine);
427+
}
428+
425429
// Split lines into words for comparison
426430
$oldWords = $this->splitIntoWords($oldLine);
427431
$newWords = $this->splitIntoWords($newLine);
428-
432+
429433
// Get word-level diff operations
430434
$wordOps = $this->calculateDiff($oldWords, $newWords);
431-
435+
432436
// Render word-level diff
433437
return $this->renderWordLevelHtml($wordOps, $oldWords, $newWords);
434438
}
@@ -479,6 +483,38 @@ private function generateCheckboxDiff(string $oldLine, string $newLine): string
479483
return $prefix . $oldCheckbox . '' . $newCheckbox . $oldSuffix;
480484
}
481485

486+
/**
487+
* Check if this is a callout block type change
488+
*
489+
* @param string $oldLine
490+
* @param string $newLine
491+
* @return bool
492+
*/
493+
private function isCalloutBlockChange(string $oldLine, string $newLine): bool {
494+
return preg_match(self::CALLOUT_BLOCK_PATTERN, trim($oldLine)) &&
495+
preg_match(self::CALLOUT_BLOCK_PATTERN, trim($newLine));
496+
}
497+
498+
/**
499+
* Generate diff for callout block type changes
500+
*
501+
* @param string $oldLine
502+
* @param string $newLine
503+
* @return string
504+
*/
505+
private function generateCalloutBlockDiff(string $oldLine, string $newLine): string {
506+
preg_match(self::CALLOUT_BLOCK_PATTERN, trim($oldLine), $oldMatches);
507+
preg_match(self::CALLOUT_BLOCK_PATTERN, trim($newLine), $newMatches);
508+
509+
$oldType = strtolower($oldMatches[1]);
510+
$newType = strtolower($newMatches[1]);
511+
512+
$oldEmoji = self::CALLOUT_EMOJIS[$oldType] ?? 'ℹ️';
513+
$newEmoji = self::CALLOUT_EMOJIS[$newType] ?? 'ℹ️';
514+
515+
return $oldEmoji . '' . $newEmoji;
516+
}
517+
482518
/**
483519
* Format special lines (code blocks, callouts, quotes) with emojis
484520
*
@@ -552,17 +588,17 @@ private function renderWordLevelHtml(array $operations, array $oldWords, array $
552588
switch ($operation['type']) {
553589
case 'add':
554590
$word = $newWords[$operation['new_line']] ?? '';
555-
// Add arrow if previous operation was a deletion
591+
// Add arrow if previous operation was a deletion (showing replacement)
556592
if ($lastWasDel) {
557-
$html .= '<ins>' . htmlspecialchars($word, ENT_QUOTES, 'UTF-8') . '</ins>';
593+
$html .= '' . htmlspecialchars($word, ENT_QUOTES, 'UTF-8');
558594
} else {
559-
$html .= '<ins>' . htmlspecialchars($word, ENT_QUOTES, 'UTF-8') . '</ins>';
595+
$html .= htmlspecialchars($word, ENT_QUOTES, 'UTF-8');
560596
}
561597
$lastWasDel = false;
562598
break;
563599
case 'remove':
564600
$word = $oldWords[$operation['old_line']] ?? '';
565-
$html .= '<del>' . htmlspecialchars($word, ENT_QUOTES, 'UTF-8') . '</del>';
601+
$html .= htmlspecialchars($word, ENT_QUOTES, 'UTF-8');
566602
$lastWasDel = true;
567603
break;
568604
case 'keep':
@@ -572,7 +608,7 @@ private function renderWordLevelHtml(array $operations, array $oldWords, array $
572608
break;
573609
}
574610
}
575-
611+
576612
return $html;
577613
}
578614
}

0 commit comments

Comments
 (0)