Last active
December 22, 2015 03:28
-
-
Save hyeonseok/6410108 to your computer and use it in GitHub Desktop.
Word diff to HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
http://hyeonseok.com/soojung/dev/2013/09/02/743.html | |
git diff -U1 --word-diff > ../diff.txt | |
Execute this command from repository then run this script. | |
*/ | |
$diff_file = file('diff.txt'); | |
$count = 1; | |
$diff_data = array(); | |
foreach ($diff_file as $row) { | |
if (strpos($row, 'diff --git') !== false) { | |
$count = 1; | |
} | |
if (strpos($row, '@@') === false) { | |
array_push($diff_data, $row); | |
} else { | |
array_push($diff_data, "\n" . '검토의견 ' . $count++ . ')' . "\n"); | |
} | |
} | |
$html = implode('', $diff_data); | |
$html = htmlspecialchars($html); | |
$html = str_replace('[-', '<del style="color: #c00">', $html); | |
$html = str_replace('-]', '</del>', $html); | |
$html = str_replace('{+', '<ins style="color: #0c0">', $html); | |
$html = str_replace('+}', '</ins>', $html); | |
$html = nl2br($html); | |
$html = '<!DOCTYPE html><html lang="ko"><head><meta charset="UTF-8"><title>DIFF</title></head><body>' . $html . '</body></html>'; | |
fwrite(fopen('diff.html', 'w'), $html); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment