Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 24, 2021
1 parent aea187c commit 94d0af0
Show file tree
Hide file tree
Showing 64 changed files with 389 additions and 550 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
.DS_Store
*.log
.nyc_output/
coverage/
node_modules/
mdast-util-to-hast.js
mdast-util-to-hast.min.js
yarn.lock
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
.nyc_output/
coverage/
mdast-util-to-hast.js
mdast-util-to-hast.min.js
*.md
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
'use strict'
module.exports = require('./lib')
export {toHast} from './lib/index.js'
8 changes: 2 additions & 6 deletions lib/all.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict'
import {one} from './one.js'

module.exports = all

var one = require('./one')

function all(h, parent) {
export function all(h, parent) {
var nodes = parent.children || []
var length = nodes.length
var values = []
Expand Down
12 changes: 4 additions & 8 deletions lib/footer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
'use strict'
import {thematicBreak} from './handlers/thematic-break.js'
import {list} from './handlers/list.js'
import {wrap} from './wrap.js'

module.exports = generateFootnotes

var thematicBreak = require('./handlers/thematic-break')
var list = require('./handlers/list')
var wrap = require('./wrap')

function generateFootnotes(h) {
export function footer(h) {
var footnoteById = h.footnoteById
var footnoteOrder = h.footnoteOrder
var length = footnoteOrder.length
Expand Down
10 changes: 3 additions & 7 deletions lib/handlers/blockquote.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict'
import {wrap} from '../wrap.js'
import {all} from '../all.js'

module.exports = blockquote

var wrap = require('../wrap')
var all = require('../all')

function blockquote(h, node) {
export function blockquote(h, node) {
return h(node, 'blockquote', wrap(all(h, node), true))
}
8 changes: 2 additions & 6 deletions lib/handlers/break.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
'use strict'
import {u} from 'unist-builder'

module.exports = hardBreak

var u = require('unist-builder')

function hardBreak(h, node) {
export function hardBreak(h, node) {
return [h(node, 'br'), u('text', '\n')]
}
8 changes: 2 additions & 6 deletions lib/handlers/code.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict'
import {u} from 'unist-builder'

module.exports = code

var u = require('unist-builder')

function code(h, node) {
export function code(h, node) {
var value = node.value ? node.value + '\n' : ''
// To do: next major, use `node.lang` w/o regex, the splitting’s been going
// on for years in remark now.
Expand Down
8 changes: 2 additions & 6 deletions lib/handlers/delete.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
'use strict'
import {all} from '../all.js'

module.exports = strikethrough

var all = require('../all')

function strikethrough(h, node) {
export function strikethrough(h, node) {
return h(node, 'del', all(h, node))
}
8 changes: 2 additions & 6 deletions lib/handlers/emphasis.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
'use strict'
import {all} from '../all.js'

module.exports = emphasis

var all = require('../all')

function emphasis(h, node) {
export function emphasis(h, node) {
return h(node, 'em', all(h, node))
}
10 changes: 3 additions & 7 deletions lib/handlers/footnote-reference.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
'use strict'
import {u} from 'unist-builder'

module.exports = footnoteReference

var u = require('unist-builder')

function footnoteReference(h, node) {
export function footnoteReference(h, node) {
var footnoteOrder = h.footnoteOrder
var identifier = String(node.identifier)

if (footnoteOrder.indexOf(identifier) === -1) {
if (!footnoteOrder.includes(identifier)) {
footnoteOrder.push(identifier)
}

Expand Down
12 changes: 4 additions & 8 deletions lib/handlers/footnote.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict'
import {footnoteReference} from './footnote-reference.js'

module.exports = footnote

var footnoteReference = require('./footnote-reference')

function footnote(h, node) {
export function footnote(h, node) {
var footnoteById = h.footnoteById
var footnoteOrder = h.footnoteOrder
var identifier = 1
Expand All @@ -21,14 +17,14 @@ function footnote(h, node) {

footnoteById[identifier] = {
type: 'footnoteDefinition',
identifier: identifier,
identifier,
children: [{type: 'paragraph', children: node.children}],
position: node.position
}

return footnoteReference(h, {
type: 'footnoteReference',
identifier: identifier,
identifier,
position: node.position
})
}
8 changes: 2 additions & 6 deletions lib/handlers/heading.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
'use strict'
import {all} from '../all.js'

module.exports = heading

var all = require('../all')

function heading(h, node) {
export function heading(h, node) {
return h(node, 'h' + node.depth, all(h, node))
}
8 changes: 2 additions & 6 deletions lib/handlers/html.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict'

module.exports = html

var u = require('unist-builder')
import {u} from 'unist-builder'

// Return either a `raw` node in dangerous mode, otherwise nothing.
function html(h, node) {
export function html(h, node) {
return h.dangerous ? h.augment(node, u('raw', node.value)) : null
}
10 changes: 3 additions & 7 deletions lib/handlers/image-reference.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict'
import normalize from 'mdurl/encode.js'
import {revert} from '../revert.js'

module.exports = imageReference

var normalize = require('mdurl/encode')
var revert = require('../revert')

function imageReference(h, node) {
export function imageReference(h, node) {
var def = h.definition(node.identifier)
var props

Expand Down
8 changes: 2 additions & 6 deletions lib/handlers/image.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict'
import normalize from 'mdurl/encode.js'

var normalize = require('mdurl/encode')

module.exports = image

function image(h, node) {
export function image(h, node) {
var props = {src: normalize(node.url), alt: node.alt}

if (node.title !== null && node.title !== undefined) {
Expand Down
69 changes: 45 additions & 24 deletions lib/handlers/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
'use strict'
import {blockquote} from './blockquote.js'
import {hardBreak} from './break.js'
import {code} from './code.js'
import {strikethrough} from './delete.js'
import {emphasis} from './emphasis.js'
import {footnoteReference} from './footnote-reference.js'
import {footnote} from './footnote.js'
import {heading} from './heading.js'
import {html} from './html.js'
import {imageReference} from './image-reference.js'
import {image} from './image.js'
import {inlineCode} from './inline-code.js'
import {linkReference} from './link-reference.js'
import {link} from './link.js'
import {listItem} from './list-item.js'
import {list} from './list.js'
import {paragraph} from './paragraph.js'
import {root} from './root.js'
import {strong} from './strong.js'
import {table} from './table.js'
import {text} from './text.js'
import {thematicBreak} from './thematic-break.js'

module.exports = {
blockquote: require('./blockquote'),
break: require('./break'),
code: require('./code'),
delete: require('./delete'),
emphasis: require('./emphasis'),
footnoteReference: require('./footnote-reference'),
footnote: require('./footnote'),
heading: require('./heading'),
html: require('./html'),
imageReference: require('./image-reference'),
image: require('./image'),
inlineCode: require('./inline-code'),
linkReference: require('./link-reference'),
link: require('./link'),
listItem: require('./list-item'),
list: require('./list'),
paragraph: require('./paragraph'),
root: require('./root'),
strong: require('./strong'),
table: require('./table'),
text: require('./text'),
thematicBreak: require('./thematic-break'),
export const handlers = {
blockquote,
break: hardBreak,
code,
delete: strikethrough,
emphasis,
footnoteReference,
footnote,
heading,
html,
imageReference,
image,
inlineCode,
linkReference,
link,
listItem,
list,
paragraph,
root,
strong,
table,
text,
thematicBreak,
toml: ignore,
yaml: ignore,
definition: ignore,
Expand Down
8 changes: 2 additions & 6 deletions lib/handlers/inline-code.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict'
import {u} from 'unist-builder'

module.exports = inlineCode

var u = require('unist-builder')

function inlineCode(h, node) {
export function inlineCode(h, node) {
var value = node.value.replace(/\r?\n|\r/g, ' ')
return h(node, 'code', [u('text', value)])
}
12 changes: 4 additions & 8 deletions lib/handlers/link-reference.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
'use strict'
import normalize from 'mdurl/encode.js'
import {revert} from '../revert.js'
import {all} from '../all.js'

module.exports = linkReference

var normalize = require('mdurl/encode')
var revert = require('../revert')
var all = require('../all')

function linkReference(h, node) {
export function linkReference(h, node) {
var def = h.definition(node.identifier)
var props

Expand Down
10 changes: 3 additions & 7 deletions lib/handlers/link.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict'
import normalize from 'mdurl/encode.js'
import {all} from '../all.js'

var normalize = require('mdurl/encode')
var all = require('../all')

module.exports = link

function link(h, node) {
export function link(h, node) {
var props = {href: normalize(node.url)}

if (node.title !== null && node.title !== undefined) {
Expand Down
10 changes: 3 additions & 7 deletions lib/handlers/list-item.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict'
import {u} from 'unist-builder'
import {all} from '../all.js'

module.exports = listItem

var u = require('unist-builder')
var all = require('../all')

function listItem(h, node, parent) {
export function listItem(h, node, parent) {
var result = all(h, node)
var head = result[0]
var loose = parent ? listLoose(parent) : listItemLoose(node)
Expand Down
12 changes: 4 additions & 8 deletions lib/handlers/list.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict'
import {wrap} from '../wrap.js'
import {all} from '../all.js'

module.exports = list

var wrap = require('../wrap')
var all = require('../all')

function list(h, node) {
export function list(h, node) {
var props = {}
var name = node.ordered ? 'ol' : 'ul'
var items
Expand All @@ -23,7 +19,7 @@ function list(h, node) {
while (++index < length) {
if (
items[index].properties.className &&
items[index].properties.className.indexOf('task-list-item') !== -1
items[index].properties.className.includes('task-list-item')
) {
props.className = ['contains-task-list']
break
Expand Down
8 changes: 2 additions & 6 deletions lib/handlers/paragraph.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
'use strict'
import {all} from '../all.js'

module.exports = paragraph

var all = require('../all')

function paragraph(h, node) {
export function paragraph(h, node) {
return h(node, 'p', all(h, node))
}
12 changes: 4 additions & 8 deletions lib/handlers/root.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict'
import {u} from 'unist-builder'
import {all} from '../all.js'
import {wrap} from '../wrap.js'

module.exports = root

var u = require('unist-builder')
var wrap = require('../wrap')
var all = require('../all')

function root(h, node) {
export function root(h, node) {
return h.augment(node, u('root', wrap(all(h, node))))
}
Loading

0 comments on commit 94d0af0

Please sign in to comment.