Skip to content

Commit 24fd914

Browse files
committed
Change to match CommonMark
* remark now complies to CommonMark, this means that we can adhere too, and prefer the first if duplicate definitions are found. Previously, this was an option and defaulted to `false`. It’s no longer possible to change the behavior of this utility.
1 parent f306df4 commit 24fd914

File tree

4 files changed

+9
-34
lines changed

4 files changed

+9
-34
lines changed

index.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,23 @@ function getDefinitionFactory(node, options) {
1212
}
1313

1414
// Gather all definitions in `node`
15-
function gather(node, options) {
15+
function gather(node) {
1616
var cache = {}
1717

1818
if (!node || !node.type) {
1919
throw new Error('mdast-util-definitions expected node')
2020
}
2121

22-
visit(node, 'definition', options && options.commonmark ? commonmark : normal)
22+
visit(node, 'definition', ondefinition)
2323

2424
return cache
2525

26-
function commonmark(definition) {
26+
function ondefinition(definition) {
2727
var id = normalise(definition.identifier)
2828
if (!own.call(cache, id)) {
2929
cache[id] = definition
3030
}
3131
}
32-
33-
function normal(definition) {
34-
cache[normalise(definition.identifier)] = definition
35-
}
3632
}
3733

3834
// Factory to get a node from the given definition-cache.

readme.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,12 @@ definition('foo')
4545

4646
## API
4747

48-
### `definitions(node[, options])`
48+
### `definitions(tree)`
4949

50-
Create a cache of all [definition][]s in [`node`][node].
50+
Create a cache of all [definition][]s in [`tree`][node].
5151

52-
###### `options.commonmark`
53-
54-
`boolean`, default: false — Turn on (`true`) to use CommonMark precedence:
55-
ignore definitions found later for duplicate definitions.
56-
The default behavior is to prefer the last found definition.
52+
Uses CommonMark precedence: prefers the first definitions for duplicate
53+
definitions.
5754

5855
###### Returns
5956

test.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,8 @@ test('mdast-util-definitions', function (t) {
7373

7474
t.deepEqual(
7575
definitions(tree)('example').url,
76-
'https://two.com',
77-
'should prefer the last of duplicate definitions by default'
78-
)
79-
80-
t.deepEqual(
81-
definitions(tree, {commonmark: true})('example').url,
8276
'https://one.com',
83-
'should prefer the first of duplicate definitions in commonmark mode'
77+
'should prefer the first of duplicate definitions'
8478
)
8579

8680
t.end()

types/index.d.ts

+1-13
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ import {Node} from 'unist'
33
import {Definition} from 'mdast'
44

55
declare namespace definitions {
6-
interface Options {
7-
/**
8-
* Turn on (`true`) to use CommonMark precedence: ignore definitions found later for duplicate definitions. The default behavior is to prefer the last found definition.
9-
*
10-
* @default false
11-
*/
12-
commonmark: boolean
13-
}
14-
156
/**
167
* @param identifier [Identifier](https://github.com/syntax-tree/mdast#association) of [definition](https://github.com/syntax-tree/mdast#definition).
178
*/
@@ -21,9 +12,6 @@ declare namespace definitions {
2112
/**
2213
* Create a cache of all [definition](https://github.com/syntax-tree/mdast#definition)s in [`node`](https://github.com/syntax-tree/unist#node).
2314
*/
24-
declare function definitions(
25-
node: Node,
26-
options?: definitions.Options
27-
): definitions.DefinitionCache
15+
declare function definitions(node: Node): definitions.DefinitionCache
2816

2917
export = definitions

0 commit comments

Comments
 (0)