# coding: utf-8 # Rakefile for Markdown documents. DIRMAP_MD = '.dirmap.md' HTML2PDF = "wkhtmltopdf -B 1cm -L 1.5cm -R 1.5cm -T 1.5cm -s A4 --encoding UTF-8 " TEX2IMAGE = "tex2image" IMAGEMAGICK = "convert -alpha deactivate -density 144x144" INKSCAPE = "inkscape" require "pp" require "fileutils" require "pathname" require "tempfile" require "rake/clean" ## .dirmap.md # dirmap コマンドは必ず実行なので task タスク。 # これを file にすると存在するときに実行されない。 # 生成物の .dirmap.md から task タスクへの依存を設定すると、 # .dirmap.md に依存する file タスクに「必ず実行」が伝播して必ず実行になってしまう。 # DIRMAP_MD というファイルに対する file タスクへの依存として扱うことで、 # .dirmap.md に依存する file タスクに「必ず実行」が伝播するのを防いでいる。 desc "update .dirmap.md if directory changed." file DIRMAP_MD => :dirmap_command task :dirmap_command do sh "dirmap --kakasi" end ## *.html md_files = FileList["*.md"] html_files = md_files.ext("html") html_tasks = [] html_files.each do |html_file| md_file = html_file.ext("md") md_path = Pathname.new( md_file) dirpath = md_path.dirname src = FileList[md_file, DIRMAP_MD] file html_file => [DIRMAP_MD, md_file] do puts "Update: #{md_file} -> #{html_file}" side_lines = `pandoc #{DIRMAP_MD}`.split("\n") side_lines.unshift "
" line = `pandoc -s -N --toc -c madowu.css --mathjax --filter pandoc-crossref #{md_file}` lines = line.split("\n") end_body = lines.index('