This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
109 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,124 @@ | ||
import test from 'tape' | ||
import assert from 'node:assert/strict' | ||
import test from 'node:test' | ||
import {remark} from 'remark' | ||
import remarkHtml from 'remark-html' | ||
import remarkUnwrapImages from './index.js' | ||
|
||
test('remarkUnwrapImages', (t) => { | ||
t.equal( | ||
remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.processSync('') | ||
.toString(), | ||
'<img src="there.png" alt="hi">\n', | ||
'should unwrap images' | ||
) | ||
test('remarkUnwrapImages', async function (t) { | ||
await t.test('should unwrap images', async function () { | ||
assert.equal( | ||
String( | ||
await remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.process('') | ||
), | ||
'<img src="there.png" alt="hi">\n' | ||
) | ||
}) | ||
|
||
t.equal( | ||
remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.processSync(' ') | ||
.toString(), | ||
'<img src="alpha.png" alt="alpha">\n \n<img src="bravo.png" alt="bravo">\n', | ||
'should unwrap multiple images' | ||
) | ||
await t.test('should unwrap multiple images', async function () { | ||
assert.equal( | ||
String( | ||
await remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.process(' ') | ||
), | ||
'<img src="alpha.png" alt="alpha">\n \n<img src="bravo.png" alt="bravo">\n' | ||
) | ||
}) | ||
|
||
t.equal( | ||
remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.processSync('some text  an image') | ||
.toString(), | ||
'<p>some text <img src="and.png" alt="and"> an image</p>\n', | ||
'should not unwrap images next to other content' | ||
await t.test( | ||
'should not unwrap images next to other content', | ||
async function () { | ||
assert.equal( | ||
String( | ||
await remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.process('some text  an image') | ||
), | ||
'<p>some text <img src="and.png" alt="and"> an image</p>\n' | ||
) | ||
} | ||
) | ||
|
||
t.equal( | ||
remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.processSync('some text') | ||
.toString(), | ||
'<p>some text</p>\n', | ||
'should not unwrap if there are no images' | ||
) | ||
await t.test('should not unwrap if there are no images', async function () { | ||
assert.equal( | ||
String( | ||
await remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.process('some text') | ||
), | ||
'<p>some text</p>\n' | ||
) | ||
}) | ||
|
||
t.equal( | ||
remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.processSync('[](#remark)') | ||
.toString(), | ||
'<p><a href="#remark"></a></p>\n', | ||
'should not unwrap if there are no images in links' | ||
await t.test( | ||
'should not unwrap if there are no images in links', | ||
async function () { | ||
assert.equal( | ||
String( | ||
await remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.process('[](#remark)') | ||
), | ||
'<p><a href="#remark"></a></p>\n' | ||
) | ||
} | ||
) | ||
|
||
t.equal( | ||
remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.processSync('[](#remark)') | ||
.toString(), | ||
'<a href="#remark"><img src="there.png" alt="hi"></a>\n', | ||
'should supports links' | ||
) | ||
await t.test('should supports links', async function () { | ||
assert.equal( | ||
String( | ||
await remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.process('[](#remark)') | ||
), | ||
'<a href="#remark"><img src="there.png" alt="hi"></a>\n' | ||
) | ||
}) | ||
|
||
t.equal( | ||
remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.processSync('[](#remark)!') | ||
.toString(), | ||
'<p><a href="#remark"><img src="there.png" alt="hi"></a>!</p>\n', | ||
'should not unwrap links next to other content' | ||
await t.test( | ||
'should not unwrap links next to other content', | ||
async function () { | ||
assert.equal( | ||
String( | ||
await remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.process('[](#remark)!') | ||
), | ||
'<p><a href="#remark"><img src="there.png" alt="hi"></a>!</p>\n' | ||
) | ||
} | ||
) | ||
|
||
t.equal( | ||
remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.processSync('[, world](#remark)') | ||
.toString(), | ||
'<p><a href="#remark"><img src="there.png" alt="Hello">, world</a></p>\n', | ||
'should not unwrap links with other content' | ||
) | ||
|
||
t.equal( | ||
remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.processSync('![hi][image]\n\n[image]: kitten.png') | ||
.toString(), | ||
'<img src="kitten.png" alt="hi">\n', | ||
'should supports image references' | ||
) | ||
await t.test('should not unwrap links with other content', async function () { | ||
assert.equal( | ||
String( | ||
await remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.process('[, world](#remark)') | ||
), | ||
'<p><a href="#remark"><img src="there.png" alt="Hello">, world</a></p>\n' | ||
) | ||
}) | ||
|
||
t.end() | ||
await t.test('should supports image references', async function () { | ||
assert.equal( | ||
String( | ||
await remark() | ||
.use(remarkUnwrapImages) | ||
.use(remarkHtml) | ||
.process('![hi][image]\n\n[image]: kitten.png') | ||
), | ||
'<img src="kitten.png" alt="hi">\n' | ||
) | ||
}) | ||
}) |