Skip to content

Commit b8303dd

Browse files
committed
Add support for commonmark definition mode
1 parent d933bd9 commit b8303dd

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ var footer = require('./footer');
1313

1414
/* Factory to transform. */
1515
function factory(tree, options) {
16-
var dangerous = (options || {}).allowDangerousHTML;
16+
var settings = options || {};
17+
var dangerous = settings.allowDangerousHTML;
1718

1819
h.dangerous = dangerous;
19-
h.definition = definitions(tree);
20+
h.definition = definitions(tree, settings);
2021
h.footnotes = [];
2122
h.augment = augment;
2223

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"collapse-white-space": "^1.0.0",
2323
"detab": "^2.0.0",
2424
"has": "^1.0.1",
25-
"mdast-util-definitions": "^1.1.1",
25+
"mdast-util-definitions": "^1.2.0",
2626
"normalize-uri": "^1.0.0",
2727
"trim": "0.0.1",
2828
"trim-lines": "^1.0.0",

readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ Whether to allow `html` nodes and inject them as raw HTML (`boolean`,
4444
default: `false`). Only do this when compiling later with
4545
`hast-util-to-html`.
4646

47+
###### `options.commonmark`
48+
49+
Set to `true` (default: `false`) to prefer the first when duplicate definitions
50+
are found. The default behaviour is to prefer the last duplicate definition.
51+
4752
###### Returns
4853

4954
[`HASTNode`][hast].

test/definition.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,33 @@ test('Definition', function (t) {
1515
'should ignore `definition`'
1616
);
1717

18+
t.deepEqual(
19+
to(u('paragraph', [
20+
u('linkReference', {identifier: 'alpha'}, [u('text', 'bravo')]),
21+
u('definition', {identifier: 'alpha', url: 'http://charlie.com'}),
22+
u('definition', {identifier: 'alpha', url: 'http://delta.com'})
23+
])),
24+
u('element', {tagName: 'p', properties: {}}, [
25+
u('element', {tagName: 'a', properties: {href: 'http://delta.com'}}, [
26+
u('text', 'bravo')
27+
])
28+
]),
29+
'should prefer the last definition by default'
30+
);
31+
32+
t.deepEqual(
33+
to(u('paragraph', [
34+
u('linkReference', {identifier: 'alpha'}, [u('text', 'bravo')]),
35+
u('definition', {identifier: 'alpha', url: 'http://charlie.com'}),
36+
u('definition', {identifier: 'alpha', url: 'http://delta.com'})
37+
]), {commonmark: true}),
38+
u('element', {tagName: 'p', properties: {}}, [
39+
u('element', {tagName: 'a', properties: {href: 'http://charlie.com'}}, [
40+
u('text', 'bravo')
41+
])
42+
]),
43+
'should prefer the first definition in commonmark mode'
44+
);
45+
1846
t.end();
1947
});

0 commit comments

Comments
 (0)