summaryrefslogtreecommitdiff
path: root/localworddiff
blob: 1c4077afab1d2c2f8a0bcaa336e156e3607857dc (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 {
  41. float: right;
  42. width: 90%;
  43. }
  44. .file .hunk del,
  45. .file .hunk ins {
  46. font-weight: bold;
  47. }
  48. .file .hunk del {
  49. color: darkred;
  50. }
  51. .file .hunk ins {
  52. color: darkgreen;
  53. }
  54. </style>
  55. </head>
  56. <body>
  57. EOF
  58. perl -MText::WordDiff -E 'say word_diff "'"$1"'", "'"$2"'", { STYLE => 'HTMLTwoLines' }' >> "$3"
  59. cat >> "$3" <<EOF
  60. </body>
  61. </html>
  62. EOF