diff --git a/README.md b/README.md index c8a40c1..e5f6861 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,14 @@ markdown verb *.markdown markdowny version ``` +### content + +> Extract the content from one or more files. + +```sh +markdowny content *.markdown +``` + ### count > Counts the number of words excluding the YAML header and displays it. diff --git a/src/tools/content.ts b/src/tools/content.ts new file mode 100644 index 0000000..6393949 --- /dev/null +++ b/src/tools/content.ts @@ -0,0 +1,40 @@ +import * as _ from "lodash"; +import * as fs from "fs"; +import * as scanner from "../scanner"; +import * as yargs from "yargs"; + +export var command = "content"; +export var describe = "Extracts the content of the file without metadata"; + +export function builder(yargs: yargs.Arguments) +{ + return yargs + .help("help") + + .option( + "output", + { + alias: "o", + default: "-", + describe: "Write output to a file or `-` for standard out", + } + ) + + .demand(1); +} + +export function handler(argv: any) +{ + // Parse through the files and retrieve the metadata. + var files = argv._.splice(1); + var data: any = scanner.scanFiles(argv, files); + var output = data.map(x => x.__content).join("\n"); + + // Figure out where to write. + if (argv.output === "-") + { + console.log(output); + } else { + fs.writeFileSync(argv.output, Buffer.from(output, "utf-8")); + } +}