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

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 5, 2021
1 parent 7ff0d54 commit c1f8a05
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
33 changes: 15 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import {parse} from 'space-separated-tokens'
import absolute from 'is-absolute-url'
import extend from 'extend'

var defaultTarget = '_blank'
var defaultRel = ['nofollow', 'noopener', 'noreferrer']
var defaultProtocols = ['http', 'https']
const defaultTarget = '_blank'
const defaultRel = ['nofollow', 'noopener', 'noreferrer']
const defaultProtocols = ['http', 'https']

export default function remarkExternalLinks(options) {
var settings = options || {}
var target = settings.target
var rel = settings.rel
var protocols = settings.protocols || defaultProtocols
var content = settings.content
var contentProperties = settings.contentProperties || {}
const settings = options || {}
const target = settings.target
let rel = settings.rel
const protocols = settings.protocols || defaultProtocols
let content = settings.content
const contentProperties = settings.contentProperties || {}

if (typeof rel === 'string') {
rel = parse(rel)
Expand All @@ -27,25 +27,22 @@ export default function remarkExternalLinks(options) {
return transform

function transform(tree) {
var definition = definitions(tree)
const definition = definitions(tree)

visit(tree, ['link', 'linkReference'], visitor)

function visitor(node) {
var ctx = node.type === 'link' ? node : definition(node.identifier)
var protocol
var data
var props
const ctx = node.type === 'link' ? node : definition(node.identifier)

// Undefined references can be injected into the tree by plugins.
/* c8 ignore next */
if (!ctx) return

protocol = ctx.url.slice(0, ctx.url.indexOf(':'))
const protocol = ctx.url.slice(0, ctx.url.indexOf(':'))

if (absolute(ctx.url) && protocols.indexOf(protocol) !== -1) {
data = node.data || (node.data = {})
props = data.hProperties || (data.hProperties = {})
if (absolute(ctx.url) && protocols.includes(protocol)) {
const data = node.data || (node.data = {})
const props = data.hProperties || (data.hProperties = {})

if (target !== false) {
props.target = target || defaultTarget
Expand Down
9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"remark-html": "^13.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 @@ -71,13 +71,6 @@
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off",
"unicorn/prefer-includes": "off",
"import/no-extraneous-dependencies": "off"
},
"ignore": [
"types/"
]
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {remark} from 'remark'
import html from 'remark-html'
import externalLinks from './index.js'

var input = [
const input = [
'[remark](https://github.com/remarkjs/remark)',
'',
'[relative link](./example.md) and [fragment link](#fragment)',
Expand All @@ -18,7 +18,7 @@ var input = [
'<test@example.com>'
].join('\n')

test('remark-external-links', function (t) {
test('remark-external-links', (t) => {
t.equal(
remark().use(externalLinks).use(html).processSync(input).toString(),
[
Expand Down

0 comments on commit c1f8a05

Please sign in to comment.