Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 6, 2021
1 parent dbe47bf commit b78778b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
var visit = require('unist-util-visit')
var whiteSpace = require('hast-util-whitespace')

module.exports = unwrapImages
import visit from 'unist-util-visit'
import whiteSpace from 'hast-util-whitespace'

var unknown = null
var containsImage = true
var containsOther = false

var splice = [].splice

function unwrapImages() {
export default function remarkUnwrapImages() {
return transform
}

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
"Michele Bertoli <michele@berto.li>",
"José Luis Sandoval Alaguna <alagunasalahaddin@live.com> (https://uzmani.tech/)"
],
"types": "types/index.d.ts",
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"types/index.d.ts",
"index.js"
],
"dependencies": {
Expand Down
52 changes: 32 additions & 20 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
var remark = require('remark')
var html = require('remark-html')
var test = require('tape')
var unwrap = require('.')
import test from 'tape'
import remark from 'remark'
import remarkHtml from 'remark-html'
import remarkUnwrapImages from './index.js'

test('remark-unwrap-images', function (t) {
test('remarkUnwrapImages', function (t) {
t.equal(
remark().use(unwrap).use(html).processSync('![hi](there.png)').toString(),
remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('![hi](there.png)')
.toString(),
'<img src="there.png" alt="hi">\n',
'should unwrap images'
)

t.equal(
remark()
.use(unwrap)
.use(html)
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('![alpha](alpha.png) ![bravo](bravo.png)')
.toString(),
'<img src="alpha.png" alt="alpha">\n \n<img src="bravo.png" alt="bravo">\n',
Expand All @@ -22,30 +26,38 @@ test('remark-unwrap-images', function (t) {

t.equal(
remark()
.use(unwrap)
.use(html)
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('some text ![and](and.png) an image')
.toString(),
'<p>some text <img src="and.png" alt="and"> an image</p>\n',
'should not unwrap images next to other content'
)

t.equal(
remark().use(unwrap).use(html).processSync('some text').toString(),
remark()
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('some text')
.toString(),
'<p>some text</p>\n',
'should not unwrap if there are no images'
)

t.equal(
remark().use(unwrap).use(html).processSync('[](#remark)').toString(),
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'
)

t.equal(
remark()
.use(unwrap)
.use(html)
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('[![hi](there.png)](#remark)')
.toString(),
'<a href="#remark"><img src="there.png" alt="hi"></a>\n',
Expand All @@ -54,8 +66,8 @@ test('remark-unwrap-images', function (t) {

t.equal(
remark()
.use(unwrap)
.use(html)
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('[![hi](there.png)](#remark)!')
.toString(),
'<p><a href="#remark"><img src="there.png" alt="hi"></a>!</p>\n',
Expand All @@ -64,8 +76,8 @@ test('remark-unwrap-images', function (t) {

t.equal(
remark()
.use(unwrap)
.use(html)
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('[![Hello](there.png), world](#remark)')
.toString(),
'<p><a href="#remark"><img src="there.png" alt="Hello">, world</a></p>\n',
Expand All @@ -74,8 +86,8 @@ test('remark-unwrap-images', function (t) {

t.equal(
remark()
.use(unwrap)
.use(html)
.use(remarkUnwrapImages)
.use(remarkHtml)
.processSync('![hi][image]\n\n[image]: kitten.png')
.toString(),
'<img src="kitten.png" alt="hi">\n',
Expand Down

0 comments on commit b78778b

Please sign in to comment.