build-doc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/sh
  2. # script to convert a .md file (specified as a commandline argument)
  3. # into a html + pdf documentation using 'markdown' and 'pandoc'
  4. # exit if no argument given
  5. [ -z "$1" ] && { echo "Error: Usage: build-doc [filename]"; exit 1; }
  6. # compiling md to html (raw)
  7. markdown -o "precomp.html" "$1"
  8. # get directory of script
  9. basename="$(dirname $0)"
  10. # add code background + correct media path (for pandoc)
  11. # (made crossplatfarm by assuming BSD-like SED)
  12. sed "s/<pre><code>/<div><pre><code>/g;
  13. s/<\/code><\/pre>/<\/code><\/pre><\/div>/g;
  14. s/media\//\.\.\/media\//g;" precomp.html > tmp.html &&
  15. mv tmp.html precomp.html
  16. pre="<!DOCTYPE html>
  17. <html>
  18. <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
  19. <title>gizmo documentation</title>
  20. <style>
  21. body {
  22. padding-top: 100px;
  23. padding-bottom: 10px;
  24. max-width: 800px;
  25. margin: auto;
  26. }
  27. .over {
  28. border: 1px solid black;
  29. padding: 20px;
  30. border-radius: 5px;
  31. background: white;
  32. margin-bottom: 50px;
  33. }
  34. div {
  35. padding: 1px;
  36. padding-left: 10px;
  37. background: lightgrey;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <div class=\"over\">"
  43. precomp=$(cat "precomp.html")
  44. after="</div>
  45. </body>
  46. <hr>
  47. <center>
  48. follow this project on
  49. <a href="https://github.com/noahvogt/gizmo">github</a>
  50. </center>
  51. </html>"
  52. # cat together all pieces for the output
  53. echo "$pre$precomp$after" > "$basename/documentation.html"
  54. # correct media path (for pandoc)
  55. # (made crossplatfarm by assuming BSD-like SED)
  56. if [ $basename != "." ]; then
  57. sed "s/\"\.\.\//\"/g;" "$basename/documentation.html" > tmp.html
  58. mv tmp.html "$basename/pandoc.html"
  59. else
  60. cp "$basename/documentation.html" "$basename/pandoc.html"
  61. fi
  62. pandoc "$basename/pandoc.html" -f html -t pdf -o "$basename/documentation.pdf"
  63. # remove temporary file
  64. rm precomp.html "$basename/pandoc.html"