Urara-Blog/node_modules/.pnpm-store/v3/files/e4/21b5e3c7d3b5efd0ad108662e8b9b903e2b33f2777d5ad01484210eaadb557bee5aec895923d60afd2d1a4c188ea9369134038fc287c2302b2ec0e9b41ddc2
2022-08-14 01:14:53 +08:00

21 lines
564 B
Text

/**
* @typedef {import('hast').Parent} Parent
* @typedef {import('hast').Root} Root
* @typedef {Root|Parent['children'][number]} Node
*/
/**
* Rank of a heading: H1 -> 1, H2 -> 2, etc.
*
* @param {Node} node
* @returns {number|null}
*/
export function headingRank(node) {
var name =
(node && node.type === 'element' && node.tagName.toLowerCase()) || ''
var code =
name.length === 2 && name.charCodeAt(0) === 104 /* `h` */
? name.charCodeAt(1)
: 0
return code > 48 /* `0` */ && code < 55 /* `7` */ ? code - 48 /* `0` */ : null
}