Added the macroPaths option.

This commit is contained in:
David Soulayrol 2022-09-04 16:23:30 +02:00
parent 7514082b97
commit 3c39ad7ad1
3 changed files with 39 additions and 0 deletions

View File

@ -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.

View File

@ -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])

View File

@ -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!')
})
})