uniorg-slug
Advanced tools
Comparing version 0.3.1 to 0.4.0
@@ -14,8 +14,9 @@ "use strict"; | ||
const slugger = new github_slugger_1.default(); | ||
unist_util_visit_1.default(tree, 'headline', (node) => { | ||
unist_util_visit_1.default(tree, 'section', (section) => { | ||
var _a; | ||
const data = (node.data = node.data || {}); | ||
const headline = section.children[0]; | ||
const data = (headline.data = headline.data || {}); | ||
const props = (data.hProperties = data.hProperties || {}); | ||
if (!props.id) { | ||
const id = (_a = customId(node)) !== null && _a !== void 0 ? _a : slugger.slug(orgast_util_to_string_1.toString(node.title)); | ||
const id = (_a = customId(section)) !== null && _a !== void 0 ? _a : slugger.slug(orgast_util_to_string_1.toString(headline)); | ||
props.id = id; | ||
@@ -27,7 +28,6 @@ } | ||
exports.uniorgSlug = uniorgSlug; | ||
function customId(headline) { | ||
var _a, _b; | ||
const section = headline.children[0]; | ||
const drawer = (_a = section === null || section === void 0 ? void 0 : section.children) === null || _a === void 0 ? void 0 : _a.find((node) => node.type === 'property-drawer'); | ||
const property = (_b = drawer === null || drawer === void 0 ? void 0 : drawer.children) === null || _b === void 0 ? void 0 : _b.find((node) => node.type === 'node-property' && node.key === 'CUSTOM_ID'); | ||
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; | ||
@@ -34,0 +34,0 @@ } |
{ | ||
"name": "uniorg-slug", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "uniorg plugin to add `id` attributes to headlines", | ||
@@ -40,3 +40,3 @@ "keywords": [ | ||
"github-slugger": "^1.3.0", | ||
"orgast-util-to-string": "^0.3.1", | ||
"orgast-util-to-string": "^0.4.0", | ||
"unist-util-visit": "^2.0.3" | ||
@@ -53,9 +53,9 @@ }, | ||
"unified": "^9.2.1", | ||
"uniorg": "^0.3.0", | ||
"uniorg-parse": "^0.3.1", | ||
"uniorg-rehype": "^0.3.1", | ||
"uniorg": "^0.4.0", | ||
"uniorg-parse": "^0.4.0", | ||
"uniorg-rehype": "^0.4.0", | ||
"unist-util-find": "^1.0.2", | ||
"vfile": "^4.2.1" | ||
}, | ||
"gitHead": "9606f8482e4fd9229e80cafe4d40c9e0ce840a9e" | ||
"gitHead": "1b493e95f00096108fbd2f3e56c739ba0458483d" | ||
} |
Sorry, the diff of this file is not supported yet
46415
+ Addedorgast-util-to-string@0.4.5(transitive)
- Removedorgast-util-to-string@0.3.1(transitive)
Updatedorgast-util-to-string@^0.4.0