|  | 
| 1 | 1 | /** | 
| 2 | 2 |  * @typedef {import('mdast').Heading} Heading | 
| 3 |  | - * @typedef {'atx'|'atx-closed'|'setext'} Style | 
| 4 | 3 |  */ | 
| 5 | 4 | 
 | 
| 6 | 5 | /** | 
|  | 6 | + * @typedef {'atx' | 'atx-closed' | 'setext'} Style | 
|  | 7 | + *   Style of heading. | 
|  | 8 | + */ | 
|  | 9 | + | 
|  | 10 | +/** | 
|  | 11 | + * Get the heading style of a heading, optionally `relative` to a preferred | 
|  | 12 | + * style. | 
|  | 13 | + * | 
|  | 14 | + * This is because ATX headings with a depth of three or more could be | 
|  | 15 | + * considered setext. | 
|  | 16 | + * | 
| 7 | 17 |  * @param {Heading} node | 
| 8 |  | - * @param {Style} [relative] | 
| 9 |  | - * @returns {Style|null} | 
|  | 18 | + *   Heading node to check. | 
|  | 19 | + * @param {Style | null | undefined} [relative] | 
|  | 20 | + *   Relative style. | 
|  | 21 | + * @returns {Style | null} | 
|  | 22 | + *   Style, if it can be inferred. | 
| 10 | 23 |  */ | 
| 11 | 24 | export function headingStyle(node, relative) { | 
| 12 | 25 |   const last = node.children[node.children.length - 1] | 
| 13 | 26 |   const depth = node.depth | 
| 14 |  | -  const pos = node && node.position && node.position.end | 
|  | 27 | +  const pos = node.position && node.position.end | 
| 15 | 28 |   const final = last && last.position && last.position.end | 
| 16 | 29 | 
 | 
| 17 | 30 |   if (!pos) { | 
| @@ -44,8 +57,8 @@ export function headingStyle(node, relative) { | 
| 44 | 57 |  * Get the probable style of an atx-heading, depending on preferred style. | 
| 45 | 58 |  * | 
| 46 | 59 |  * @param {number} depth | 
| 47 |  | - * @param {Style|undefined} relative | 
| 48 |  | - * @returns {Style|null} | 
|  | 60 | + * @param {Style | null | undefined} relative | 
|  | 61 | + * @returns {Style | null} | 
| 49 | 62 |  */ | 
| 50 | 63 | function consolidate(depth, relative) { | 
| 51 | 64 |   return depth < 3 | 
|  | 
0 commit comments