summaryrefslogtreecommitdiff
path: root/localworddiff
blob: a1ec03aab28d816fc3ef80ee23e33caab8b9821d (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. <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css" />
  32. <style>
  33. .fileheader {
  34. display: none;
  35. visibility: hidden;
  36. }
  37. .file {
  38. float: left;
  39. width: 49%;
  40. }
  41. .file .hunk {
  42. float: right;
  43. width: 90%;
  44. }
  45. .file .hunk del,
  46. .file .hunk ins {
  47. font-weight: bold;
  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