diff --git a/README.md b/README.md index a054de8..8924ea0 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ Here are the options handled by the plugin. A good share of them is used to conf - `macroPackages` is an array of macros to use. By default, the plugin tries to choose a classical macro package using the file extension. +- `macroPaths` is an array of additional paths to search for macros. The default value is empty, see `man groff_tmac` for further explanation about the search sequence. + - `preprocessors` is an array of preprocessors to be used by **groff**. Common preprocessors are `tbl`, `pic` or `soelim`. It is empty by default. - `pattern` is the matcher used to determine the files to be transformed. It is used with **[minimatch][]**. The default value (`**/*.@(me|mm|ms|mom)`) matches all files ending with `.ms`, `.me`, `.mm` or `.mom` at any depth. diff --git a/lib/index.js b/lib/index.js index 8f288aa..89bba81 100644 --- a/lib/index.js +++ b/lib/index.js @@ -38,6 +38,7 @@ function plugin (options) { encoding: 'utf8', exe: 'groff', macroPackages: [], + macroPaths: [], preprocessors: [], pattern: '**/*.@(me|mm|ms|mom)', source: false @@ -73,6 +74,17 @@ function plugin (options) { return arguments } + var configureMacroPaths = function (paths) { + let arguments = [] + + paths.forEach(p => { + arguments.push('-M') + arguments.push(p) + }) + + return arguments + } + var configurePreprocessors = function (preprocessors) { const mapping = { chem: '-j', @@ -103,6 +115,7 @@ function plugin (options) { let arguments = [] arguments.push(configurePreprocessors(pluginOptions.preprocessors)) + arguments.push(configureMacroPaths(pluginOptions.macroPaths)) arguments.push(configureMacroPackages(pluginOptions.macroPackages, filename)) arguments.push(['-K', pluginOptions.encoding]) diff --git a/test/index.js b/test/index.js index 1d3bc55..67b1b3d 100644 --- a/test/index.js +++ b/test/index.js @@ -75,6 +75,30 @@ describe('metalsmith-groff', function () { assert.strictEqual(arguments.shift(), macros.shift(), 'Unexpected macro!') } } + assert.equal(macros.length, 0, 'Macros mismatch!') + }) + }) + + it('should use the given paths for the macros', function (done) { + let paths = ['/tmp', './here', '../another/path'] + + run(done, 'macros', { + macroPaths: paths + }, function (filename, file, log) { + let arguments = file.contents.toString('utf8').split(' ') + + while (arguments.length > 0) { + let item = arguments.shift() + + if (item === '-M') { + /* Order is not important. */ + let p = arguments.shift(), + i = paths.indexOf(p) + assert.notEqual(i, -1, 'Found unknown path!') + paths.splice(i, 1) + } + } + assert.equal(paths.length, 0, 'Paths mismatch!') }) })