uniorg-slug
Advanced tools
Comparing version 0.4.8 to 0.5.0
@@ -1,16 +0,9 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.uniorgSlug = void 0; | ||
const unist_util_visit_1 = __importDefault(require("unist-util-visit")); | ||
const github_slugger_1 = __importDefault(require("github-slugger")); | ||
const orgast_util_to_string_1 = require("orgast-util-to-string"); | ||
const uniorgSlug = (options = {}) => { | ||
import { visit } from 'unist-util-visit'; | ||
import GithubSlugger from 'github-slugger'; | ||
import { toString } from 'orgast-util-to-string'; | ||
export const uniorgSlug = (options = {}) => { | ||
return transformer; | ||
function transformer(tree, _file) { | ||
const slugger = new github_slugger_1.default(); | ||
unist_util_visit_1.default(tree, 'section', (section) => { | ||
var _a; | ||
const slugger = new GithubSlugger(); | ||
visit(tree, 'section', (section) => { | ||
const headline = section.children[0]; | ||
@@ -20,3 +13,3 @@ const data = (headline.data = headline.data || {}); | ||
if (!props.id) { | ||
const id = (_a = customId(section)) !== null && _a !== void 0 ? _a : slugger.slug(orgast_util_to_string_1.toString(headline)); | ||
const id = customId(section) ?? slugger.slug(toString(headline)); | ||
props.id = id; | ||
@@ -27,10 +20,8 @@ } | ||
}; | ||
exports.uniorgSlug = uniorgSlug; | ||
function customId(section) { | ||
var _a; | ||
const drawer = section.children.find((node) => node.type === 'property-drawer'); | ||
const property = (_a = drawer === null || drawer === void 0 ? void 0 : drawer.children) === null || _a === void 0 ? void 0 : _a.find((node) => node.type === 'node-property' && node.key === 'CUSTOM_ID'); | ||
return property === null || property === void 0 ? void 0 : property.value; | ||
const property = drawer?.children?.find((node) => node.type === 'node-property' && node.key === 'CUSTOM_ID'); | ||
return property?.value; | ||
} | ||
exports.default = exports.uniorgSlug; | ||
export default uniorgSlug; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "uniorg-slug", | ||
"version": "0.4.8", | ||
"version": "0.5.0", | ||
"type": "module", | ||
"description": "uniorg plugin to add `id` attributes to headlines", | ||
@@ -40,21 +41,20 @@ "keywords": [ | ||
"github-slugger": "^1.3.0", | ||
"orgast-util-to-string": "^0.4.5", | ||
"unist-util-visit": "^2.0.3" | ||
"orgast-util-to-string": "^0.5.0", | ||
"unist-util-visit": "4.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/github-slugger": "^1.3.0", | ||
"@types/jest": "^26.0.23", | ||
"@types/unist": "^2.0.3", | ||
"@types/vfile": "^4.0.0", | ||
"jest": "^26.6.3", | ||
"rehype-stringify": "^8.0.0", | ||
"typescript": "^4.3.2", | ||
"unified": "^9.2.1", | ||
"uniorg": "^0.4.0", | ||
"uniorg-parse": "^0.4.5", | ||
"uniorg-rehype": "^0.4.8", | ||
"@types/jest": "27.4.1", | ||
"@types/unist": "2.0.6", | ||
"jest": "27.5.1", | ||
"rehype-stringify": "9.0.3", | ||
"typescript": "4.6.3", | ||
"unified": "10.1.2", | ||
"uniorg": "^0.5.0", | ||
"uniorg-parse": "^0.5.0", | ||
"uniorg-rehype": "^0.5.0", | ||
"unist-util-find": "^1.0.2", | ||
"vfile": "^4.2.1" | ||
"vfile": "5.3.2" | ||
}, | ||
"gitHead": "14f804eaedebff32e74004498baa4c7c30a823b4" | ||
"gitHead": "e77afd8255895985eaa8b0cf15de8edab81a89b6" | ||
} |
@@ -11,7 +11,6 @@ # `uniorg-slug` | ||
## Use | ||
```js | ||
import unified from 'unified'; | ||
import { unified } from 'unified'; | ||
import uniorgParse from 'uniorg-parse'; | ||
@@ -44,2 +43,3 @@ import { uniorgSlug } from 'uniorg-slug'; | ||
will output: | ||
``` | ||
@@ -52,5 +52,4 @@ <h1 id="headline">headline</h1> | ||
## License | ||
[GNU General Public License v3.0 or later](./LICENSE) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12
Yes
40039
6
29
53
+ Addedorgast-util-to-string@0.5.6(transitive)
+ Addedunist-util-is@5.2.1(transitive)
+ Addedunist-util-visit@4.1.0(transitive)
+ Addedunist-util-visit-parents@5.1.3(transitive)
- Removedorgast-util-to-string@0.4.5(transitive)
- Removedunist-util-is@4.1.0(transitive)
- Removedunist-util-visit@2.0.3(transitive)
- Removedunist-util-visit-parents@3.1.1(transitive)
Updatedorgast-util-to-string@^0.5.0
Updatedunist-util-visit@4.1.0