Skip to content

Commit

Permalink
Added the --EOL option to control line-endings. Fixes #92.
Browse files Browse the repository at this point in the history
  • Loading branch information
75lb committed Aug 30, 2024
1 parent b891451 commit d9106f5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Node.js CI

on:
push:
branches: [ master ]
branches: [ master, next ]
pull_request:
branches: [ master ]

Expand All @@ -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
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
14 changes: 10 additions & 4 deletions lib/dmd-options.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
7 changes: 7 additions & 0 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<a name="someclass"></a>\r\n\r\n## someclass\r\nis a class\r\n\r\n')
})


module.exports = { test, only, skip }

0 comments on commit d9106f5

Please sign in to comment.