Skip to content

Commit 0bcf8cb

Browse files
committed
Add resourceLink option
1 parent c4313fb commit 0bcf8cb

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

lib/handle/link.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function link(node, _, context) {
1414
var value
1515
var stack
1616

17-
if (formatLinkAsAutolink(node)) {
17+
if (formatLinkAsAutolink(node, context)) {
1818
// Hide the fact that we’re in phrasing, because escapes don’t work.
1919
stack = context.stack
2020
context.stack = []
@@ -65,6 +65,6 @@ function link(node, _, context) {
6565
return value
6666
}
6767

68-
function linkPeek(node) {
69-
return formatLinkAsAutolink(node) ? '<' : '['
68+
function linkPeek(node, _, context) {
69+
return formatLinkAsAutolink(node, context) ? '<' : '['
7070
}

lib/util/format-code-as-indented.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module.exports = formatCodeAsIndented
22

33
function formatCodeAsIndented(node, context) {
44
return (
5-
node.value &&
65
!context.options.fences &&
6+
node.value &&
77
// If there’s no info…
88
!node.lang &&
99
// And there’s a non-whitespace character…

lib/util/format-link-as-autolink.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ module.exports = formatLinkAsAutolink
22

33
var toString = require('mdast-util-to-string')
44

5-
function formatLinkAsAutolink(node) {
5+
function formatLinkAsAutolink(node, context) {
66
var raw = toString(node)
77

88
return (
9+
!context.options.resourceLink &&
910
// If there’s a url…
1011
node.url &&
1112
// And there’s a no title…

readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ otherwise) (`'one'`, `'tab'`, or `'mixed'`, default: `'tab'`).
109109

110110
Marker to use to serialize titles (`'"'` or `"'"`, default: `'"'`).
111111

112+
###### `options.resourceLink`
113+
114+
Whether to use reference links always (`boolean`, default: `false`).
115+
The default is to use autolinks (`<https://example.com>`) when possible.
116+
112117
###### `options.rule`
113118

114119
Marker to use for thematic breaks (`'*'`, `'-'`, or `'_'`, default: `'*'`).

test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,19 @@ test('link', function (t) {
14591459
'should use an autolink for nodes w/ a value similar to the url and a protocol'
14601460
)
14611461

1462+
t.equal(
1463+
to(
1464+
{
1465+
type: 'link',
1466+
url: 'tel:123',
1467+
children: [{type: 'text', value: 'tel:123'}]
1468+
},
1469+
{resourceLink: true}
1470+
),
1471+
'[tel:123](tel:123)\n',
1472+
'should use a resource link (`resourceLink: true`)'
1473+
)
1474+
14621475
t.equal(
14631476
to({
14641477
type: 'link',

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ declare namespace toMarkdown {
6464
incrementListMarker?: boolean
6565
listItemIndent?: 'tab' | 'one' | 'mixed'
6666
quote?: '"' | "'"
67+
resourceLink?: boolean
6768
rule?: '-' | '_' | '*'
6869
ruleRepetition?: number
6970
ruleSpaces?: boolean

0 commit comments

Comments
 (0)