"use strict"; var gulp = require("gulp"), gulpLoadPlugins = require("gulp-load-plugins"), del = require("del"), fs = require("fs"), path = require("path"), through = require("through2"), roaster = require("roaster"), pdf = require("html-pdf"); var $ = gulpLoadPlugins(), opts = { isDebug: Boolean($.util.env.debug), md: {}, pdf: { type: "pdf", width: "8.5in", height: "11in", border: "0in", // handled via CSS }, }, errLogger = function(err) { $.util.log($.util.colors.red("Error: "), String(opts.isDebug ? err.stack : err)); throw err; }, md2html = function(opts) { if (!opts) opts = {}; var tmplPath = opts.template ? fs.realpathSync(opts.template) : path.join(__dirname, "/src/template/index.html"), tmpl = fs.readFileSync(tmplPath, "utf8"); return through.obj(function(file, encoding, done) { var md = file.contents.toString(); file.path = file.path.replace(/\.md$/, ".html"); roaster(md, opts, function(err, contents) { if (err) return done(err); var html = tmpl.replace("{{content}}", contents); file.contents = new Buffer(html); done(null, file); }); }); }, html2pdf = function(opts) { if (!opts) opts = {}; return through.obj(function(file, encoding, done) { var baseUri = "file://" + path.dirname(file.path) + "/", html = file.contents.toString() .replace("
", "\n