Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rehype-autolink-headings

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-autolink-headings - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

52

index.js

@@ -1,12 +0,12 @@

'use strict';
'use strict'
var extend = require('extend');
var visit = require('unist-util-visit');
var has = require('hast-util-has-property');
var is = require('hast-util-is-element');
var extend = require('extend')
var visit = require('unist-util-visit')
var has = require('hast-util-has-property')
var is = require('hast-util-is-element')
module.exports = autolink;
module.exports = autolink
var headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
var methods = {prepend: 'unshift', append: 'push'};
var headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']
var methods = {prepend: 'unshift', append: 'push'}
var contentDefaults = {

@@ -17,23 +17,23 @@ type: 'element',

children: []
};
}
function autolink(options) {
var settings = options || {};
var props = settings.properties;
var behavior = settings.behaviour || settings.behavior || 'prepend';
var content = settings.content || contentDefaults;
var fn = behavior === 'wrap' ? wrap : inject;
var settings = options || {}
var props = settings.properties
var behavior = settings.behaviour || settings.behavior || 'prepend'
var content = settings.content || contentDefaults
var fn = behavior === 'wrap' ? wrap : inject
if (behavior !== 'wrap' && !props) {
props = {ariaHidden: true};
props = {ariaHidden: 'true'}
}
if (content && typeof content === 'object' && !('length' in content)) {
content = [content];
content = [content]
}
return transformer;
return transformer
function transformer(tree) {
visit(tree, visitor);
visit(tree, visitor)
}

@@ -43,3 +43,3 @@

if (is(node, headings) && has(node, 'id')) {
fn(node);
fn(node)
}

@@ -49,11 +49,11 @@ }

function wrap(node) {
var child = icon(node);
child.children = node.children;
node.children = [child];
var child = icon(node)
child.children = node.children
node.children = [child]
}
function inject(node) {
var child = icon(node);
child.children = extend(true, content);
node.children[methods[behavior]](child);
var child = icon(node)
child.children = extend(true, content)
node.children[methods[behavior]](child)
}

@@ -66,4 +66,4 @@

properties: extend({}, props, {href: '#' + node.properties.id})
};
}
}
}
{
"name": "rehype-autolink-headings",
"version": "2.0.2",
"version": "2.0.3",
"description": "Add links to headings in HTML",

@@ -13,4 +13,4 @@ "license": "MIT",

],
"repository": "https://github.com/wooorm/rehype-autolink-headings",
"bugs": "https://github.com/wooorm/rehype-autolink-headings/issues",
"repository": "rehypejs/rehype-autolink-headings",
"bugs": "https://github.com/rehypejs/rehype-autolink-headings/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",

@@ -31,23 +31,23 @@ "contributors": [

"bail": "^1.0.1",
"browserify": "^14.1.0",
"esmangle": "^1.0.0",
"browserify": "^16.0.0",
"is-hidden": "^1.0.1",
"negate": "^1.0.0",
"nyc": "^11.0.0",
"rehype": "^5.0.0",
"remark-cli": "^4.0.0",
"remark-preset-wooorm": "^3.0.0",
"nyc": "^12.0.0",
"prettier": "^1.13.7",
"rehype": "^6.0.0",
"remark-cli": "^5.0.0",
"remark-preset-wooorm": "^4.0.0",
"tape": "^4.0.0",
"to-vfile": "^2.1.1",
"xo": "^0.18.0"
"tinyify": "^2.4.3",
"to-vfile": "^5.0.0",
"xo": "^0.21.0"
},
"scripts": {
"build-md": "remark . -qfo",
"build-bundle": "browserify index.js --bare -s rehypeAutolinkHeadings > rehype-autolink-headings.js",
"build-mangle": "esmangle rehype-autolink-headings.js > rehype-autolink-headings.min.js",
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"lint": "xo",
"test-api": "node test/index.js",
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
"build-bundle": "browserify index.js -s rehypeAutolinkHeadings > rehype-autolink-headings.js",
"build-mangle": "browserify index.js -s rehypeAutolinkHeadings -p tinyify > rehype-autolink-headings.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test/index.js",
"test": "npm run build && npm run lint && npm run test-coverage"
"test": "npm run format && npm run build && npm run test-coverage"
},

@@ -60,4 +60,12 @@ "nyc": {

},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"space": true,
"prettier": true,
"esnext": false,

@@ -64,0 +72,0 @@ "ignores": [

@@ -15,3 +15,3 @@ # rehype-autolink-headings [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]

Say we have the following fragment:
Say we have the following file, `fragment.html`:

@@ -29,8 +29,8 @@ ```html

```javascript
var fs = require('fs');
var rehype = require('rehype');
var slug = require('rehype-slug');
var link = require('rehype-autolink-headings');
var fs = require('fs')
var rehype = require('rehype')
var slug = require('rehype-slug')
var link = require('rehype-autolink-headings')
var doc = fs.readFileSync('fragment.html');
var doc = fs.readFileSync('fragment.html')

@@ -41,6 +41,6 @@ rehype()

.use(link)
.process(doc, function (err, file) {
if (err) throw err;
console.log(String(file));
});
.process(doc, function(err, file) {
if (err) throw err
console.log(String(file))
})
```

@@ -86,4 +86,12 @@

* [`rehype-slug`](https://github.com/wooorm/rehype-slug)
* [`rehype-slug`](https://github.com/rehypejs/rehype-slug)
## Contribute
See [`contributing.md` in `rehypejs/rehype`][contribute] for ways to get
started.
This organisation has a [Code of Conduct][coc]. By interacting with this
repository, organisation, or community you agree to abide by its terms.
## License

@@ -95,9 +103,9 @@

[travis-badge]: https://img.shields.io/travis/wooorm/rehype-autolink-headings.svg
[travis-badge]: https://img.shields.io/travis/rehypejs/rehype-autolink-headings.svg
[travis]: https://travis-ci.org/wooorm/rehype-autolink-headings
[travis]: https://travis-ci.org/rehypejs/rehype-autolink-headings
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/rehype-autolink-headings.svg
[codecov-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-autolink-headings.svg
[codecov]: https://codecov.io/github/wooorm/rehype-autolink-headings
[codecov]: https://codecov.io/github/rehypejs/rehype-autolink-headings

@@ -110,2 +118,6 @@ [npm]: https://docs.npmjs.com/cli/install

[rehype]: https://github.com/wooorm/rehype
[rehype]: https://github.com/rehypejs/rehype
[contribute]: https://github.com/rehypejs/rehype/blob/master/contributing.md
[coc]: https://github.com/rehypejs/rehype/blob/master/code-of-conduct.md
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc