remark-inline-links
Advanced tools
Comparing version 3.1.3 to 4.0.0
55
index.js
'use strict' | ||
var visit = require('unist-util-visit') | ||
var remove = require('unist-util-remove') | ||
var getDefinitions = require('mdast-util-definitions') | ||
@@ -13,40 +12,40 @@ | ||
function transformer(tree) { | ||
var reference = referenceFactory(tree, options) | ||
var definitions = getDefinitions(tree, options) | ||
visit(tree, ['imageReference', 'linkReference'], reference) | ||
visit(tree, onvisit) | ||
remove(tree, 'definition') | ||
} | ||
} | ||
function onvisit(node, index, parent) { | ||
var definition | ||
var replacement | ||
var image | ||
// Factory to transform a reference based on `definitions`. | ||
function referenceFactory(tree, options) { | ||
var definitions = getDefinitions(tree, options) | ||
if (node.type === 'definition') { | ||
parent.children.splice(index, 1) | ||
return [visit.SKIP, index] | ||
} | ||
return reference | ||
if (node.type === 'imageReference' || node.type === 'linkReference') { | ||
definition = definitions(node.identifier) | ||
// Transform a reference based on bound `definitions`. | ||
function reference(node, index, parent) { | ||
var definition = definitions(node.identifier) | ||
var replacement | ||
var image | ||
if (definition) { | ||
image = node.type === 'imageReference' | ||
if (definition) { | ||
image = node.type === 'imageReference' | ||
replacement = { | ||
type: image ? 'image' : 'link', | ||
url: definition.url, | ||
title: definition.title | ||
} | ||
replacement = { | ||
type: image ? 'image' : 'link', | ||
url: definition.url, | ||
title: definition.title | ||
} | ||
if (image) { | ||
replacement.alt = node.alt | ||
} else { | ||
replacement.children = node.children | ||
} | ||
if (image) { | ||
replacement.alt = node.alt | ||
} else { | ||
replacement.children = node.children | ||
parent.children[index] = replacement | ||
return [visit.SKIP, index] | ||
} | ||
} | ||
parent.children[index] = replacement | ||
} | ||
} | ||
} |
{ | ||
"name": "remark-inline-links", | ||
"version": "3.1.3", | ||
"version": "4.0.0", | ||
"description": "remark plugin to transform references and definitions into normal links and images", | ||
@@ -9,2 +9,3 @@ "license": "MIT", | ||
"remark", | ||
"remark-plugin", | ||
"plugin", | ||
@@ -21,2 +22,6 @@ "mdast", | ||
"bugs": "https://github.com/remarkjs/remark-inline-links/issues", | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/unified" | ||
}, | ||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", | ||
@@ -27,5 +32,4 @@ "contributors": [ | ||
"dependencies": { | ||
"mdast-util-definitions": "^1.1.1", | ||
"unist-util-remove": "^1.0.0", | ||
"unist-util-visit": "^1.1.0" | ||
"mdast-util-definitions": "^2.0.0", | ||
"unist-util-visit": "^2.0.0" | ||
}, | ||
@@ -37,10 +41,10 @@ "files": [ | ||
"browserify": "^16.0.0", | ||
"nyc": "^14.0.0", | ||
"prettier": "^1.0.0", | ||
"remark": "^10.0.0", | ||
"remark-cli": "^6.0.0", | ||
"remark-preset-wooorm": "^5.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^2.0.0", | ||
"remark": "^11.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.0.0", | ||
"xo": "^0.24.0" | ||
"xo": "^0.28.0" | ||
}, | ||
@@ -47,0 +51,0 @@ "scripts": { |
@@ -67,7 +67,13 @@ # remark-inline-links | ||
Handle definitions as commonmark (`boolean`, default: `false`). | ||
The default behaviour is to prefer the last found duplicate definition. | ||
Handle definitions as CommonMark (`boolean`, default: `false`). | ||
The default behavior is to prefer the last found duplicate definition. | ||
Turn on to use CommonMark handling of duplicate definitions: use the first | ||
definition, ignore duplicate definitions. | ||
## Security | ||
Use of `remark-inline-links` does not involve [**rehype**][rehype] | ||
([**hast**][hast]) or user content so there are no openings for | ||
[cross-site scripting (XSS)][xss] attacks. | ||
## Related | ||
@@ -92,4 +98,4 @@ | ||
This project has a [Code of Conduct][coc]. | ||
By interacting with this repository, organisation, or community you agree to | ||
This project has a [code of conduct][coc]. | ||
By interacting with this repository, organization, or community you agree to | ||
abide by its terms. | ||
@@ -125,3 +131,3 @@ | ||
[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg | ||
@@ -145,1 +151,7 @@ [chat]: https://spectrum.chat/unified/remark | ||
[remark]: https://github.com/remarkjs/remark | ||
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting | ||
[rehype]: https://github.com/rehypejs/rehype | ||
[hast]: https://github.com/syntax-tree/hast |
8626
2
154
+ Added@types/unist@2.0.11(transitive)
+ Addedmdast-util-definitions@2.0.1(transitive)
+ Addedunist-util-is@4.1.0(transitive)
+ Addedunist-util-visit@2.0.3(transitive)
+ Addedunist-util-visit-parents@3.1.1(transitive)
- Removedunist-util-remove@^1.0.0
- Removedmdast-util-definitions@1.2.5(transitive)
- Removedunist-util-is@3.0.0(transitive)
- Removedunist-util-remove@1.0.3(transitive)
- Removedunist-util-visit@1.4.1(transitive)
- Removedunist-util-visit-parents@2.1.2(transitive)
Updatedunist-util-visit@^2.0.0