summaryrefslogtreecommitdiff
path: root/localworddiff
blob: 4ee12d6cc7e25055933bc1837db6262ce131dc38 (plain)
  1. #!/bin/sh
  2. #
  3. # Copyright © 2013 Jonas Smedegaard <dr@jones.dk>
  4. # Description: Generate word-based diff for console or web
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # Depends: libtext-worddiff-perl (>= 0.08)
  20. #
  21. # TODO: rewrite as Perl script, using HTML::HTML5::Builder
  22. set -e
  23. if [ -z "$3" ]; then
  24. perl -MText::WordDiff -E 'say word_diff "'"$1"'", "'"$2"'", { STYLE => 'ANSIColor' }'
  25. exit
  26. fi
  27. cat > "$3" <<EOF
  28. <!DOCTYPE html>
  29. <html>
  30. <head>
  31. <style>
  32. .fileheader {
  33. display: none;
  34. visibility: hidden;
  35. }
  36. .file {
  37. float: left;
  38. width: 49%;
  39. }
  40. .file .hunk del,
  41. .file .hunk ins {
  42. font-weight: bold;
  43. text-decoration: inherit;
  44. }
  45. .file .hunk del {
  46. color: darkred;
  47. }
  48. .file .hunk ins {
  49. color: darkgreen;
  50. }
  51. </style>
  52. </head>
  53. <body>
  54. EOF
  55. perl -MText::WordDiff -MText::Markdown=markdown -E '$d="<div class=\"file\">";$d_="<\/div>";foreach(split /(?:$d_\n)?$d/, word_diff "'"$1"'", "'"$2"'", { STYLE => "HTMLTwoLines" }){say $d.markdown($_).$d_ if ($_)}'>> "$3"
  56. cat >> "$3" <<EOF
  57. </body>
  58. </html>
  59. EOF