I generate PDFs from Markdown files using Rake. If a Markdown file is filename.md
, I like the PDF to be filename.md.pdf
not filename.pdf
, so that autocompletion works the way I like and so that it's clear what the source of the PDF file is.
I have this Rake file, which works fine.
MDFILES = FileList["*.md"]
PDFS = MDFILES.ext("pdf")
desc "Build PDFs of all chapters"
task :pdfs => PDFS
# Build PDFs from Markdown source
rule ".pdf" => ".md" do |t|
sh "pandoc #{t.source} -o #{t.name}"
end
If I run rake pdfs
or rake filename.pdf
the PDFs are generated as expected, but the PDFs are named filename.pdf
.
But I want the Rakefile to be this instead:
MDFILES = FileList["*.md"]
PDFS = MDFILES.ext("md.pdf")
desc "Build PDFs of all chapters"
task :pdfs => PDFS
# Build PDFs from Markdown source
rule "md.pdf" => ".md" do |t|
sh "pandoc #{t.source} -o #{t.name}"
end
Running rake pdfs
or rake filename.md.pdf
returns the error Don't know how to build task 'filename.md.pdf'
.
How can I produce filenames the way I want?
By the way, this type of rule works fine with Make, to wit:
%.md.pdf : %.md
pandoc $< -o $@