title: Grunt convert markdown to pdf recursively and dynamically
body: <p>I am stuck writing a Gruntfile which aim is to convert a bunch of Markdown files to PDF dynamically. Giving the current folder hierarchy:</p>
  
  <pre><code>root/
    |_subfolder1
    |    |_filename1.md
    |_subfolder2
         |_filename2.md
   ...
    |_node_modules
    |_subfolderN
         |filenameN.md
  </code></pre>
  
  <p>I would like to run a Markdown to PDF task which would process the md file and ouput a PDF file with the matching filename in the same output directory.</p>
  
  <p>I did create a custom task which is parsing current directory, ignoring the mode_modules folder and get the markdown file, but I don't know how to configure the md2pdf task with the good properties to reflect dynamic folder mapping.</p>
  
  <p>Here's my current Gruntfile: </p>
  
  <pre><code>module.exports = function(grunt) {
  
    // 1 - Configuration
    grunt.initConfig({
      md2pdf: {
      }
    });
  
     // 2 - Plugins
    grunt.loadNpmTasks('grunt-md2pdf');
  
    // 3 - Task registering
    grunt.registerTask('default', 'Get Subfolders', function() {
  
      grunt.file.recurse('.', callback);
  
      function callback(abspath, rootdir, subdir, filename) {
        var filenameOutExt;
  
        // if current occurence is a file subdir == undefined
        // checking subdir to true means it's not undefined and
        // the current path is a directory
        if(subdir) {
          // excluding node_modules folder
          if (!subdir.match('node_modules')) {
            // only process markdown files
            if(filename.match('.md')) {
              filenameOutExt = filename.split('.')[0];
              // now for each markdown files, run md2pdf task
              // and ouput filenameOutExt.pdf in same folder
              // as the input files
            }
          }
        }
      }
    });
  };
  </code></pre>
  
  <p>I am using this plugin: <a href="https://www.npmjs.com/package/grunt-md2pdf" rel="nofollow">https://www.npmjs.com/package/grunt-md2pdf</a></p>
  
  <p>So my questions is how should I configure the md2pdf task to pass it the markdown files and generate matching filename pdf output in same directory. </p>
  
  <p>Output should be:</p>
  
  <pre><code>root/
    |_subfolder1
    |    |_filename1.md
         |_filename1.pdf
    |_subfolder2
         |_filename2.md
         |_filename2.pdf
   ...
    |_node_modules
    |_subfolderN
         |filenameN.md
         |_filenameN.pdf
  </code></pre>
  
  <p>Thanks a lot</p>