nilfam-editor
Version:
A powerful, customizable rich-text editor built with TipTap, React, and Tailwind CSS. Supports RTL/LTR text, resizable media (images/videos), tables, code blocks, font styling, and more for an enhanced content creation experience.
20 lines (18 loc) • 580 B
JavaScript
// utils/getHeadings.ts
export function getHeadings(editor) {
const result = []
if (!editor?.state?.doc) return result
editor.state.doc.descendants(node => {
if (
node.type.name === 'heading' &&
node.textContent.trim() // متن خالی نباشد
) {
result.push({
level: node.attrs.level,
id : node.attrs.id || '', // اگر آیدی هنوز نساخته
text : node.textContent,
})
}
})
return result
}