Skip to content

Commit

Permalink
added some examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lgcavalheiro committed Dec 5, 2020
1 parent ebe603d commit f4596d4
Show file tree
Hide file tree
Showing 11 changed files with 4,243 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.nyc_output/
node_modules/
yarn.lock
package-lock.json
example/results
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"tabWidth": 4,
"useTabs": false,
"arrowParens": "avoid",
"printWidth": 128
"printWidth": 100
}
10 changes: 10 additions & 0 deletions example/basicUsage.gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const gulp = require("gulp");
const series = gulp.series;

const mammoth = require("../src/index");

function basicUsage() {
return gulp.src("./data/nonEmpty.docx").pipe(mammoth("html")).pipe(gulp.dest("./results"));
}

module.exports.default = series(basicUsage);
Binary file added example/data/convertToHtml.docx
Binary file not shown.
Binary file added example/data/convertToMarkdown.docx
Binary file not shown.
Binary file added example/data/convertToText.docx
Binary file not shown.
Binary file added example/data/nonEmpty.docx
Binary file not shown.
16 changes: 16 additions & 0 deletions example/withGulpIf.gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const gulp = require("gulp");
const gulpIf = require("gulp-if");
const series = gulp.series;

const mammoth = require("../src/index");

function withGulpIf() {
return gulp
.src("./data/*")
.pipe(gulpIf(file => file.basename.toLowerCase().includes("html"), mammoth("html")))
.pipe(gulpIf(file => file.basename.toLowerCase().includes("markdown"), mammoth("md")))
.pipe(gulpIf(file => file.basename.toLowerCase().includes("text"), mammoth("txt")))
.pipe(gulp.dest("./results"));
}

module.exports.default = series(withGulpIf);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"devDependencies": {
"coveralls": "^3.1.0",
"gulp": "^4.0.2",
"gulp-if": "^3.0.0",
"gulp-spawn-mocha-nyc": "^1.0.0",
"mocha": "^8.2.0",
"nyc": "^15.1.0",
Expand Down
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const convertLiterals = {
return through.obj(async (file, encoding, callback) => {
if (file.contents === null) callback(null, file);
else {
let { value, messages } = await mammoth.convertToMarkdown({ path: file.path }, options);
let { value, messages } = await mammoth.convertToMarkdown(
{ path: file.path },
options
);
file = handleFileContents(file, ".md", value, messages);
callback(null, file);
}
Expand Down Expand Up @@ -57,6 +60,7 @@ function handleFileContents(file, ext, value, messages) {
}

module.exports = function (convertTo, options) {
if (!convertLiterals[convertTo.toLowerCase()]) throw new PluginError(PLUGIN_NAME, "Invalid convertion format.");
if (!convertLiterals[convertTo.toLowerCase()])
throw new PluginError(PLUGIN_NAME, "Invalid convertion format.");
else return convertLiterals[convertTo.toLowerCase()](options);
};
Loading

0 comments on commit f4596d4

Please sign in to comment.