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

remark-deflist

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-deflist - npm Package Compare versions

Comparing version 0.3.0 to 1.0.0

lib/index.d.ts

216

lib/index.js

@@ -1,114 +0,106 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = deflist;
var _unistUtilVisit = _interopRequireDefault(require("unist-util-visit"));
var _mdastUtilToString = _interopRequireDefault(require("mdast-util-to-string"));
var _mdastUtilFromMarkdown = _interopRequireDefault(require("mdast-util-from-markdown"));
var _mdastUtilToMarkdown = _interopRequireDefault(require("mdast-util-to-markdown"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const isSingleDeflist = node => /^[^:].+\n:\s/.test((0, _mdastUtilToString.default)(node)) && node.type === 'paragraph';
const isSplitDeflist = (node, i, parent) => i > 0 && /^:\s/.test((0, _mdastUtilToString.default)(node)) && !/^:\s/.test((0, _mdastUtilToString.default)(parent.children[i - 1])) && node.type === 'paragraph' && parent.children[i - 1].type === 'paragraph';
/**
* Detect metadata and add it to the `data` field of a VFile.
*/
import { visit } from 'unist-util-visit';
import { toString } from 'mdast-util-to-string';
import { fromMarkdown } from 'mdast-util-from-markdown';
import { toMarkdown } from 'mdast-util-to-markdown';
// Test if deflist is contained in a single paragraph.
const isSingleDeflist = (node) =>
// i > 0 &&
/^[^:].+\n:\s/.test(toString(node)) &&
node.type === 'paragraph';
// Test if deflist is split between two paragraphs.
const isSplitDeflist = (node, i, parent) => i > 0 &&
/^:\s/.test(toString(node)) &&
!/^:\s/.test(toString(parent.children[i - 1])) &&
node.type === 'paragraph' &&
parent.children[i - 1].type === 'paragraph';
const isdeflist = (node, i, parent) => isSingleDeflist(node) || isSplitDeflist(node, i, parent);
function deflist(options = {}) {
return (tree, file) => {
(0, _unistUtilVisit.default)(tree, ['paragraph'], (node, i, parent) => {
const isdef = isdeflist(node, i, parent);
if (!isdef) {
return;
}
let dd = undefined;
let dt = undefined;
let count = 0;
let start = 0;
if (isSingleDeflist(node)) {
const [title, ...children] = (0, _mdastUtilToMarkdown.default)(node).split(/\n:\s+/);
dt = (0, _mdastUtilFromMarkdown.default)(title).children.flatMap(({
children
}) => children);
dd = children.map(_mdastUtilFromMarkdown.default).flatMap(({
children
}) => children).map(({
children
}) => ({
type: 'descriptiondetails',
data: {
hName: 'dd'
},
children
}));
start = i;
count = 1;
} else {
dt = parent.children[i - 1].children;
dd = (0, _mdastUtilToMarkdown.default)(node).replace(/^:\s+/, '').split(/\n:\s+/).map(_mdastUtilFromMarkdown.default).flatMap(({
children
}) => children).map(({
children
}) => ({
type: 'descriptiondetails',
data: {
hName: 'dd'
},
children
}));
start = i - 1;
count = 2;
}
const child = {
type: 'descriptionlist',
data: {
hName: 'dl'
},
children: [{
type: 'descriptionterm',
data: {
hName: 'dt'
},
children: dt
}, ...dd]
};
parent.children.splice(start, count, child);
});
(0, _unistUtilVisit.default)(tree, ['descriptionlist'], (node, i, parent) => {
const start = i;
let count = 1;
let children = node.children;
for (let j = i + 1; j < parent.children.length; j++) {
const next = parent.children[j];
if (next.type === 'descriptionlist') {
count++;
children = children.concat(next.children);
} else {
break;
}
}
if (count === 1) {
return;
}
node.children = children;
parent.children.splice(start, count, node);
});
};
export default function deflist() {
return (tree) => {
visit(tree, ['paragraph'], (node, i, parent) => {
const isdef = isdeflist(node, i, parent);
if (!isdef) {
return;
}
let dd = undefined;
let dt = undefined;
let count = 0;
let start = 0;
if (isSingleDeflist(node)) {
const [title, ...children] = toMarkdown(node).split(/\n:\s+/);
const childs = fromMarkdown(title).children;
dt = childs.flatMap(({ children }) => children);
dd = children
.map((str) => fromMarkdown(str))
.flatMap(({ children }) => children)
.map(({ children }) => ({
type: 'descriptiondetails',
data: {
hName: 'dd'
},
children
}));
start = i;
count = 1;
}
else {
const childs = parent.children[i - 1];
dt = childs.children;
dd = toMarkdown(node)
.replace(/^:\s+/, '')
.split(/\n:\s+/)
.map((str) => fromMarkdown(str))
.flatMap(({ children }) => children)
.map(({ children }) => ({
type: 'descriptiondetails',
data: {
hName: 'dd'
},
children
}));
start = i - 1;
count = 2;
}
const child = {
type: 'descriptionlist',
data: {
hName: 'dl'
},
children: [
{
type: 'descriptionterm',
data: {
hName: 'dt'
},
children: dt
},
...dd
]
};
parent.children.splice(start, count, child);
});
// Merge subsequent definition lists into a single list (#10)
visit(tree, ['descriptionlist'], (node, i, parent) => {
const start = i;
let count = 1;
let children = node.children;
for (let j = i + 1; j < parent.children.length; j++) {
const next = parent.children[j];
if (next.type === 'descriptionlist') {
count++;
children = children.concat(next.children);
}
else {
break;
}
}
if (count === 1) {
return;
}
node.children = children;
parent.children.splice(start, count, node);
});
};
}
module.exports = exports.default;

@@ -1,9 +0,21 @@

# The MIT License (MIT)
# MIT License
Copyright &copy; Alex Shaw
Copyright © Alex Shaw
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
{
"name": "remark-deflist",
"version": "0.3.0",
"version": "1.0.0",
"license": "MIT",
"description": "Remark plugin for pandoc-style definition lists.",
"author": "Alex Shaw <alex.shaw.as@gmail.com>",
"main": "lib/index.js",
"module": "src/index.js",
"sideEffects": false,
"type": "module",
"exports": "./lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib",
"src"
"lib/"
],

@@ -17,18 +18,14 @@ "keywords": [

],
"repository": {
"url": "https://github.com/Symbitic/remark-plugins/tree/master/packages/remark-deflist",
"type": "git"
},
"engines": {
"node": ">=8"
},
"repository": "https://github.com/Symbitic/remark-plugins/tree/master/packages/remark-deflist",
"bugs": "https://github.com/Symbitic/remark-plugins/issues",
"scripts": {
"build": "babel --root-mode upward --ignore \"**/*.spec.js\" --out-dir lib src"
"build": "tsc"
},
"dependencies": {
"mdast-util-from-markdown": "^0.8.4",
"mdast-util-to-markdown": "^0.6.1",
"mdast-util-to-string": "^2.0.0",
"unist-util-visit": "^2.0.3"
}
"mdast-util-from-markdown": "^1.0.0",
"mdast-util-to-markdown": "^1.1.1",
"mdast-util-to-string": "^3.1.0",
"unist-util-visit": "^4.0.0"
},
"gitHead": "a1bfb2a02cd6c9c2385a732f95ae44f07d03284f"
}
# remark-deflist
[![CI/CD Status](https://github.com/Symbitic/remark-plugins/workflows/main/badge.svg)](https://github.com/Symbitic/remark-plugins/actions)
[![MIT License](https://img.shields.io/github/license/Symbitic/remark-plugins)](https://github.com/Symbitic/remark-plugins/blob/master/LICENSE.md)
[![stars](https://img.shields.io/github/stars/Symbitic/remark-plugins.svg)](https://github.com/Symbitic/remark-plugins)
[Remark](https://remark.js.org/) plugin for adding support for pandoc-style definition lists to Markdown.

@@ -10,2 +14,13 @@

## Install
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
[npm](https://docs.npmjs.com/cli/install):
```sh
npm install remark-deflist
```
## Example

@@ -80,20 +95,14 @@

## Installation
```bash
npm install --save remark-deflist
```
## Usage
```javascript
import unified from 'unified'
import { unified } from 'unified'
import markdown from 'remark-parse'
import html from 'rehype-stringify'
import remark2rehype from 'remark-rehype'
import deflist from 'remark-deflist'
import meta from 'remark-meta'
unified()
.use(markdown)
.use(deflist)
.use(meta)
.use(remark2rehype)

@@ -105,5 +114,6 @@ .use(html)

[MIT](LICENSE.md) &copy; Alex Shaw
[MIT](LICENSE.md) © Alex Shaw
[pandoc]: https://pandoc.org/MANUAL.html#definition-lists
[PHP Markdown Extra]: https://michelf.ca/projects/php-markdown/extra/#def-list
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