UNPKG

laif-ds

Version:

Design System di Laif con componenti React basati su principi di Atomic Design

36 lines (35 loc) 1.1 kB
"use client"; import { encodeCharacterReference as u } from "../util/encode-character-reference.js"; import { formatHeadingAsSetext as g } from "../util/format-heading-as-setext.js"; function d(r, l, e, o) { const a = Math.max(Math.min(6, r.depth || 1), 1), i = e.createTracker(o); if (g(r, e)) { const h = e.enter("headingSetext"), x = e.enter("phrasing"), c = e.containerPhrasing(r, { ...i.current(), before: ` `, after: ` ` }); return x(), h(), c + ` ` + (a === 1 ? "=" : "-").repeat( // The whole size… c.length - // Minus the position of the character after the last EOL (or // 0 if there is none)… (Math.max(c.lastIndexOf("\r"), c.lastIndexOf(` `)) + 1) ); } const t = "#".repeat(a), s = e.enter("headingAtx"), f = e.enter("phrasing"); i.move(t + " "); let n = e.containerPhrasing(r, { before: "# ", after: ` `, ...i.current() }); return /^[\t ]/.test(n) && (n = u(n.charCodeAt(0)) + n.slice(1)), n = n ? t + " " + n : t, e.options.closeAtx && (n += " " + t), f(), s(), n; } export { d as heading };