You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since <a href="link">text</a> is nothing but [text](link) i modified the first line of the test.jsinput. :
var test = require('tape')
var remark = require('remark')
var html = require('remark-html')
var externalLinks = require('.')
var input = [
'<a href="https://github.com/remarkjs/remark">remark</a>',
'',
'[relative link](./example.md) and [fragment link](#fragment)',
'',
'[missing][], [local][], and [external][].',
'',
'[current](.) [up](..) [relative link without ./](example.md)',
'',
'[local]: #local',
'[external]: https://github.com/remarkjs/remark',
'',
'<mailto:test@example.com>'
].join('\n')
test('remark-external-links', function(t) {
t.equal(
remark()
.use(externalLinks)
.use(html)
.processSync(input)
.toString(),
[
'<p><a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">remark</a></p>',
'<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>',
'<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">external</a>.</p>',
'<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>',
'<p><a href="mailto:test@example.com">test@example.com</a></p>',
''
].join('\n'),
'should add the defaults when without options'
)
t.equal(
remark()
.use(externalLinks, {target: false, rel: false})
.use(html)
.processSync(input)
.toString(),
[
'<p><a href="https://github.com/remarkjs/remark">remark</a></p>',
'<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>',
'<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark">external</a>.</p>',
'<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>',
'<p><a href="mailto:test@example.com">test@example.com</a></p>',
''
].join('\n'),
'should do nothing if both are set to false'
)
t.equal(
remark()
.use(externalLinks, {target: '_blank', rel: false})
.use(html)
.processSync(input)
.toString(),
[
'<p><a href="https://github.com/remarkjs/remark" target="_blank">remark</a></p>',
'<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>',
'<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank">external</a>.</p>',
'<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>',
'<p><a href="mailto:test@example.com">test@example.com</a></p>',
''
].join('\n'),
'should add a target'
)
t.equal(
remark()
.use(externalLinks, {target: false, rel: 'nofollow'})
.use(html)
.processSync(input)
.toString(),
[
'<p><a href="https://github.com/remarkjs/remark" rel="nofollow">remark</a></p>',
'<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>',
'<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" rel="nofollow">external</a>.</p>',
'<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>',
'<p><a href="mailto:test@example.com">test@example.com</a></p>',
''
].join('\n'),
'should add a rel'
)
t.equal(
remark()
.use(externalLinks, {target: '_blank', rel: 'nofollow'})
.use(html)
.processSync(input)
.toString(),
[
'<p><a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow">remark</a></p>',
'<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>',
'<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow">external</a>.</p>',
'<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>',
'<p><a href="mailto:test@example.com">test@example.com</a></p>',
''
].join('\n'),
'should add both'
)
t.equal(
remark()
.use(externalLinks, {protocols: ['http', 'https', 'mailto']})
.use(html)
.processSync(input)
.toString(),
[
'<p><a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">remark</a></p>',
'<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>',
'<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">external</a>.</p>',
'<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>',
'<p><a href="mailto:test@example.com" target="_blank" rel="nofollow noopener noreferrer">test@example.com</a></p>',
''
].join('\n'),
'should add a target'
)
t.equal(
remark()
.use(externalLinks, {
content: {type: 'text', value: ' (opens in a new window)'}
})
.use(html)
.processSync(input)
.toString(),
[
'<p><a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">remark<span> (opens in a new window)</span></a></p>',
'<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>',
'<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">external<span> (opens in a new window)</span></a>.</p>',
'<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>',
'<p><a href="mailto:test@example.com">test@example.com</a></p>',
''
].join('\n'),
'should add hast node as content'
)
t.equal(
remark()
.use(externalLinks, {
content: [
{type: 'text', value: ' ('},
{
type: 'element',
tagName: 'em',
properties: {},
children: [{type: 'text', value: 'opens in a new window'}]
},
{type: 'text', value: ')'}
]
})
.use(html)
.processSync(input)
.toString(),
[
'<p><a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">remark<span> (<em>opens in a new window</em>)</span></a></p>',
'<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>',
'<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">external<span> (<em>opens in a new window</em>)</span></a>.</p>',
'<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>',
'<p><a href="mailto:test@example.com">test@example.com</a></p>',
''
].join('\n'),
'should add hast children as content'
)
t.end()
})
Command :
node test
Output :
TAP version 13
# remark-external-links
not ok 1 should add the defaults when without options
---
operator: equal
expected: |-
'<p><a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">remark</a></p>\n<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>\n<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">external</a>.</p>\n<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>\n<p><a href="mailto:test@example.com">test@example.com</a></p>\n'
actual: |-
'<p><a href="https://github.com/remarkjs/remark">remark</a></p>\n<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>\n<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">external</a>.</p>\n<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>\n<p><a href="mailto:test@example.com">test@example.com</a></p>\n'
at: Test.<anonymous> (/tmp/remark-external-links/test.js:22:5)
stack: |-
Error: should add the defaults when without options
at Test.assert [as _assert] (/tmp/remark-external-links/node_modules/tape/lib/test.js:228:54)
at Test.bound [as _assert] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.equal (/tmp/remark-external-links/node_modules/tape/lib/test.js:389:10)
at Test.bound [as equal] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.<anonymous> (/tmp/remark-external-links/test.js:22:5)
at Test.bound [as _cb] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.run (/tmp/remark-external-links/node_modules/tape/lib/test.js:96:10)
at Test.bound [as run] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Immediate.next [as _onImmediate] (/tmp/remark-external-links/node_modules/tape/lib/results.js:81:19)
at processImmediate (internal/timers.js:439:21)
...
ok 2 should do nothing if both are set to false
not ok 3 should add a target
---
operator: equal
expected: |-
'<p><a href="https://github.com/remarkjs/remark" target="_blank">remark</a></p>\n<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>\n<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank">external</a>.</p>\n<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>\n<p><a href="mailto:test@example.com">test@example.com</a></p>\n'
actual: |-
'<p><a href="https://github.com/remarkjs/remark">remark</a></p>\n<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>\n<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank">external</a>.</p>\n<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>\n<p><a href="mailto:test@example.com">test@example.com</a></p>\n'
at: Test.<anonymous> (/tmp/remark-external-links/test.js:56:5)
stack: |-
Error: should add a target
at Test.assert [as _assert] (/tmp/remark-external-links/node_modules/tape/lib/test.js:228:54)
at Test.bound [as _assert] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.equal (/tmp/remark-external-links/node_modules/tape/lib/test.js:389:10)
at Test.bound [as equal] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.<anonymous> (/tmp/remark-external-links/test.js:56:5)
at Test.bound [as _cb] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.run (/tmp/remark-external-links/node_modules/tape/lib/test.js:96:10)
at Test.bound [as run] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Immediate.next [as _onImmediate] (/tmp/remark-external-links/node_modules/tape/lib/results.js:81:19)
at processImmediate (internal/timers.js:439:21)
...
not ok 4 should add a rel
---
operator: equal
expected: |-
'<p><a href="https://github.com/remarkjs/remark" rel="nofollow">remark</a></p>\n<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>\n<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" rel="nofollow">external</a>.</p>\n<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>\n<p><a href="mailto:test@example.com">test@example.com</a></p>\n'
actual: |-
'<p><a href="https://github.com/remarkjs/remark">remark</a></p>\n<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>\n<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" rel="nofollow">external</a>.</p>\n<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>\n<p><a href="mailto:test@example.com">test@example.com</a></p>\n'
at: Test.<anonymous> (/tmp/remark-external-links/test.js:73:5)
stack: |-
Error: should add a rel
at Test.assert [as _assert] (/tmp/remark-external-links/node_modules/tape/lib/test.js:228:54)
at Test.bound [as _assert] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.equal (/tmp/remark-external-links/node_modules/tape/lib/test.js:389:10)
at Test.bound [as equal] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.<anonymous> (/tmp/remark-external-links/test.js:73:5)
at Test.bound [as _cb] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.run (/tmp/remark-external-links/node_modules/tape/lib/test.js:96:10)
at Test.bound [as run] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Immediate.next [as _onImmediate] (/tmp/remark-external-links/node_modules/tape/lib/results.js:81:19)
at processImmediate (internal/timers.js:439:21)
...
not ok 5 should add both
---
operator: equal
expected: |-
'<p><a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow">remark</a></p>\n<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>\n<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow">external</a>.</p>\n<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>\n<p><a href="mailto:test@example.com">test@example.com</a></p>\n'
actual: |-
'<p><a href="https://github.com/remarkjs/remark">remark</a></p>\n<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>\n<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow">external</a>.</p>\n<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>\n<p><a href="mailto:test@example.com">test@example.com</a></p>\n'
at: Test.<anonymous> (/tmp/remark-external-links/test.js:90:5)
stack: |-
Error: should add both
at Test.assert [as _assert] (/tmp/remark-external-links/node_modules/tape/lib/test.js:228:54)
at Test.bound [as _assert] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.equal (/tmp/remark-external-links/node_modules/tape/lib/test.js:389:10)
at Test.bound [as equal] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.<anonymous> (/tmp/remark-external-links/test.js:90:5)
at Test.bound [as _cb] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.run (/tmp/remark-external-links/node_modules/tape/lib/test.js:96:10)
at Test.bound [as run] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Immediate.next [as _onImmediate] (/tmp/remark-external-links/node_modules/tape/lib/results.js:81:19)
at processImmediate (internal/timers.js:439:21)
...
not ok 6 should add a target
---
operator: equal
expected: |-
'<p><a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">remark</a></p>\n<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>\n<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">external</a>.</p>\n<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>\n<p><a href="mailto:test@example.com" target="_blank" rel="nofollow noopener noreferrer">test@example.com</a></p>\n'
actual: |-
'<p><a href="https://github.com/remarkjs/remark">remark</a></p>\n<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>\n<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">external</a>.</p>\n<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>\n<p><a href="mailto:test@example.com" target="_blank" rel="nofollow noopener noreferrer">test@example.com</a></p>\n'
at: Test.<anonymous> (/tmp/remark-external-links/test.js:107:5)
stack: |-
Error: should add a target
at Test.assert [as _assert] (/tmp/remark-external-links/node_modules/tape/lib/test.js:228:54)
at Test.bound [as _assert] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.equal (/tmp/remark-external-links/node_modules/tape/lib/test.js:389:10)
at Test.bound [as equal] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.<anonymous> (/tmp/remark-external-links/test.js:107:5)
at Test.bound [as _cb] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.run (/tmp/remark-external-links/node_modules/tape/lib/test.js:96:10)
at Test.bound [as run] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Immediate.next [as _onImmediate] (/tmp/remark-external-links/node_modules/tape/lib/results.js:81:19)
at processImmediate (internal/timers.js:439:21)
...
not ok 7 should add hast node as content
---
operator: equal
expected: |-
'<p><a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">remark<span> (opens in a new window)</span></a></p>\n<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>\n<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">external<span> (opens in a new window)</span></a>.</p>\n<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>\n<p><a href="mailto:test@example.com">test@example.com</a></p>\n'
actual: |-
'<p><a href="https://github.com/remarkjs/remark">remark</a></p>\n<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>\n<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">external<span> (opens in a new window)</span></a>.</p>\n<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>\n<p><a href="mailto:test@example.com">test@example.com</a></p>\n'
at: Test.<anonymous> (/tmp/remark-external-links/test.js:124:5)
stack: |-
Error: should add hast node as content
at Test.assert [as _assert] (/tmp/remark-external-links/node_modules/tape/lib/test.js:228:54)
at Test.bound [as _assert] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.equal (/tmp/remark-external-links/node_modules/tape/lib/test.js:389:10)
at Test.bound [as equal] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.<anonymous> (/tmp/remark-external-links/test.js:124:5)
at Test.bound [as _cb] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.run (/tmp/remark-external-links/node_modules/tape/lib/test.js:96:10)
at Test.bound [as run] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Immediate.next [as _onImmediate] (/tmp/remark-external-links/node_modules/tape/lib/results.js:81:19)
at processImmediate (internal/timers.js:439:21)
...
not ok 8 should add hast children as content
---
operator: equal
expected: |-
'<p><a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">remark<span> (<em>opens in a new window</em>)</span></a></p>\n<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>\n<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">external<span> (<em>opens in a new window</em>)</span></a>.</p>\n<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>\n<p><a href="mailto:test@example.com">test@example.com</a></p>\n'
actual: |-
'<p><a href="https://github.com/remarkjs/remark">remark</a></p>\n<p><a href="./example.md">relative link</a> and <a href="#fragment">fragment link</a></p>\n<p>[missing][], <a href="#local">local</a>, and <a href="https://github.com/remarkjs/remark" target="_blank" rel="nofollow noopener noreferrer">external<span> (<em>opens in a new window</em>)</span></a>.</p>\n<p><a href=".">current</a> <a href="..">up</a> <a href="example.md">relative link without ./</a></p>\n<p><a href="mailto:test@example.com">test@example.com</a></p>\n'
at: Test.<anonymous> (/tmp/remark-external-links/test.js:143:5)
stack: |-
Error: should add hast children as content
at Test.assert [as _assert] (/tmp/remark-external-links/node_modules/tape/lib/test.js:228:54)
at Test.bound [as _assert] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.equal (/tmp/remark-external-links/node_modules/tape/lib/test.js:389:10)
at Test.bound [as equal] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.<anonymous> (/tmp/remark-external-links/test.js:143:5)
at Test.bound [as _cb] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Test.run (/tmp/remark-external-links/node_modules/tape/lib/test.js:96:10)
at Test.bound [as run] (/tmp/remark-external-links/node_modules/tape/lib/test.js:80:32)
at Immediate.next [as _onImmediate] (/tmp/remark-external-links/node_modules/tape/lib/results.js:81:19)
at processImmediate (internal/timers.js:439:21)
...
1..8
# tests 8
# pass 1
# fail 7
For now, I have to manually add the attributes. I am relatively inexperienced in JavaScript and thus cannot submit a PR. I hope the fix is as simple as a change in function call order.
Thanks in advance.
The text was updated successfully, but these errors were encountered:
remark works on markdown, rehype works on html (you can read more about unified on its website); dealing with raw HTML in markdown is out of scope for this project; instead, a project called rehype-external-links would be a good solution!
HTML Anchor tags aren't accounted
Hey! I'm here from
gatsby-remark-external-links
Oldschool
<a>
tags are not working.Manjaro Linux
Reproduction
Since
<a href="link">text</a>
is nothing but[text](link)
i modified the first line of thetest.js
input.
:Command :
node test
Output :
Expected behaviour
The tests should pass.
Actual behaviour
The tests fail.
Refer to this issue.
For now, I have to manually add the attributes. I am relatively inexperienced in JavaScript and thus cannot submit a PR. I hope the fix is as simple as a change in function call order.
Thanks in advance.
The text was updated successfully, but these errors were encountered: