Commit 55991da7 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Gère les fichiers .md générés.

parent f505b8f0
import { callbackify } from "util";
import { callbackify, promisify } from "util";
import exec from "./exec";
import fs from "fs";
import logger from "gulplog";
import { merge } from "merge-anything";
import { mkTempFile } from "./tempdir";
import { obj } from "through2";
import path from "path";
import PluginError from "plugin-error";
const writeFile = promisify(fs.writeFile);
const exists = promisify(fs.exists);
const PLUGIN_NAME = "pandoc";
......@@ -44,13 +50,39 @@ export default function pandoc(options = {}) {
return obj(
callbackify(
/**
* @param {File} input
* @param {import("vinyl")} input
*/
async function (input) {
const output = input.clone({ contents: false });
output.extname = ".html";
output.contents = null;
if (!(await exists(input.path))) {
const tmpFile = await mkTempFile(input);
if (input.isStream()) {
const write = fs.createWriteStream(tmpFile.path);
try {
const done = new Promise((resolve, reject) => {
write.on("close", () => resolve());
input.on("error", reject);
write.on("error", reject);
});
input.contents.pipe(write);
await done;
} finally {
write.close();
}
} else if (input.isBuffer()) {
await writeFile(tmpFile.path, input.contents, {});
} else {
throw new PluginError(
PLUGIN_NAME,
`cannot handle input ${input.inspect()}`
);
}
input = tmpFile;
}
const args = [
"--from=markdown+backtick_code_blocks+pandoc_title_block+yaml_metadata_block",
"--to=revealjs",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment