summaryrefslogtreecommitdiff
path: root/localworddiff
blob: 0ff2f7ac11f0d5a05585239b7547fe4ac2d2cc83 (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. text-decoration: inherit;
  48. }
  49. .file .hunk del {
  50. color: darkred;
  51. }
  52. .file .hunk ins {
  53. color: darkgreen;
  54. }
  55. </style>
  56. </head>
  57. <body>
  58. EOF
  59. perl -MText::WordDiff -E 'say word_diff "'"$1"'", "'"$2"'", { STYLE => "HTMLTwoLines" }' >> "$3"
  60. cat >> "$3" <<EOF
  61. </body>
  62. </html>
  63. EOF