mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-05 19:09:29 +08:00
21 lines
564 B
Text
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
|
|
}
|