Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 2, 2021
1 parent a01e3e2 commit dfa5a4b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
12 changes: 4 additions & 8 deletions core.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict'
import toText from 'hast-util-to-text'
import visit from 'unist-util-visit'

var toText = require('hast-util-to-text')
var visit = require('unist-util-visit')

module.exports = createPlugin

function createPlugin(lowlight) {
export function createPlugin(lowlight) {
return function (options) {
var settings = options || {}
var name = 'hljs'
Expand All @@ -17,7 +13,7 @@ function createPlugin(lowlight) {

if (settings.languages) {
// eslint-disable-next-line guard-for-in
for (let name in settings.languages) {
for (const name in settings.languages) {
lowlight.registerLanguage(name, settings.languages[name])
}
}
Expand Down
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict'
var lowlight = require('lowlight')
var createPlugin = require('./core')
import lowlight from 'lowlight'
import {createPlugin} from './core.js'

module.exports = createPlugin(lowlight)
export default createPlugin(lowlight)
7 changes: 3 additions & 4 deletions light.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict'
var lowlight = require('lowlight/lib/core')
var createPlugin = require('./core')
import lowlight from 'lowlight/lib/core.js'
import {createPlugin} from './core.js'

module.exports = createPlugin(lowlight)
export default createPlugin(lowlight)
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"core.js",
"index.js",
Expand All @@ -41,7 +44,7 @@
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"xo": "^0.37.0"
"xo": "^0.39.0"
},
"scripts": {
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
Expand All @@ -59,8 +62,9 @@
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off",
"unicorn/prefer-includes": "off"
}
},
Expand Down
18 changes: 8 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict'

var test = require('tape')
var rehype = require('rehype')
var highlight = require('.')
var light = require('./light')
var js = require('highlight.js/lib/languages/javascript')
var as = require('highlight.js/lib/languages/applescript')
var cp = require('highlight.js/lib/languages/cpp')
import test from 'tape'
import rehype from 'rehype'
import highlight from './index.js'
import light from './light.js'
import js from 'highlight.js/lib/languages/javascript.js'
import as from 'highlight.js/lib/languages/applescript.js'
import cp from 'highlight.js/lib/languages/cpp.js'

test('highlight()', function (t) {
t.equal(
Expand Down Expand Up @@ -414,7 +412,7 @@ test('highlight()', function (t) {
.data('settings', {fragment: true})
.use(highlight, {
languages: {
test: function () {
test() {
return {
aliases: ['test'],
keywords: {keyword: 'test'}
Expand Down

0 comments on commit dfa5a4b

Please sign in to comment.