From d9106f59c16ba27b696f1635aa6ad0b4d3e8fcf2 Mon Sep 17 00:00:00 2001 From: Lloyd Brookes Date: Fri, 30 Aug 2024 19:12:55 +0100 Subject: [PATCH] Added the --EOL option to control line-endings. Fixes #92. --- .github/workflows/node.js.yml | 4 ++-- index.js | 10 ++++++++-- lib/dmd-options.js | 14 ++++++++++---- test/api.js | 7 +++++++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 9697de9..7e5b3c1 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -4,7 +4,7 @@ name: Node.js CI on: push: - branches: [ master ] + branches: [ master, next ] pull_request: branches: [ master ] @@ -26,5 +26,5 @@ jobs: node-version: ${{ matrix.node-version }} cache: 'npm' - run: npm install - - run: npm i -g @75lb/nature + - run: npm i -g --omit=optional @75lb/nature - run: npm run test diff --git a/index.js b/index.js index b7c76e4..331c1bf 100644 --- a/index.js +++ b/index.js @@ -121,8 +121,14 @@ async function generate (templateData, options) { }) templateData.options = options const output = compiled(templateData) - dmd.cache.writeSync([inputData, inputOptions, dmdVersion], output) - return output + + let adjOutput = output + if (options.EOL) { + adjOutput = output.replace(/\r?\n/gm, options.EOL === 'posix' ? '\n' : '\r\n') + } + + dmd.cache.writeSync([inputData, inputOptions, dmdVersion], adjOutput) + return adjOutput } /* always skip the cache when custom plugins, partials or helpers are used */ diff --git a/lib/dmd-options.js b/lib/dmd-options.js index df839cf..0ef5076 100644 --- a/lib/dmd-options.js +++ b/lib/dmd-options.js @@ -1,9 +1,9 @@ /** * @typicalname options */ -function DmdOptions (options) { +function DmdOptions (options = {}) { const arrayify = require('array-back') - options = options || {} + const os = require('os') /** * The template the supplied documentation will be rendered into. Use the default or supply your own template for full control over the output. @@ -81,14 +81,14 @@ function DmdOptions (options) { this['member-index-format'] = 'grouped' /** - * If true, \{@link XXX} tags are rendered in normal text if XXX is a URL and monospace (code) format otherwise. + * By default, all {@link} tags are rendered in plain text. If `--clever-links` is set, URL {@link} tags are rendered in plain text, otherwise monospace. * @type {boolean} * @dafult */ this['clever-links'] = false /** - * If true, all \{@link} tags are rendered in monospace (code) format. This setting is ignored in `clever-links` is true. + * By default, all {@link} tags are rendered in plain text. If `--monospace-links` is set, all links are rendered in monospace format. This setting is ignored if `--clever-links` is set. * @type {boolean} * @default */ @@ -130,6 +130,12 @@ function DmdOptions (options) { * @type {array} */ this.partial = arrayify(options.partial) + + /** + * Specify ether `posix` or `win32`. Forces all line endings in the dmd output to use the specified EOL character. + * @type {string} + */ + this.EOL = options.EOL } module.exports = DmdOptions diff --git a/test/api.js b/test/api.js index 4e83311..accb2dc 100644 --- a/test/api.js +++ b/test/api.js @@ -53,4 +53,11 @@ test.set('Dmd issue #89 - Max callstack size exceeded bug', async function () { a.doesNotReject(() => dmd(templateData, options)) }) +test.set('dmd.async({ noCache }) with custom line endings', async function () { + const options = { noCache: true, EOL: 'win32' } + const result = await dmd(fixture, options) + a.equal(result, '\r\n\r\n## someclass\r\nis a class\r\n\r\n') +}) + + module.exports = { test, only, skip }