1- import { $getRoot , $getSelection , $isRangeSelection , $isTextNode , $isElementNode , ElementNode , LexicalEditor , LexicalNode , RangeSelection , TextNode } from 'lexical'
1+ import {
2+ $getRoot ,
3+ $getSelection ,
4+ $isRangeSelection ,
5+ $isTextNode ,
6+ $isElementNode ,
7+ ElementNode ,
8+ LexicalEditor ,
9+ LexicalNode ,
10+ RangeSelection ,
11+ TextNode
12+ } from 'lexical'
213import { $isLinkNode } from '@lexical/link'
314import { $isHeadingNode } from '@lexical/rich-text'
415import { $isListNode , $isListItemNode } from '@lexical/list'
@@ -130,16 +141,13 @@ export function getSelectionAsMarkdown(editor: LexicalEditor, _exportParams: Omi
130141
131142 // Get unique block-level parent nodes to preserve structure (headings, lists, paragraphs, etc.)
132143 const parentNodes = new Set < ElementNode > ( )
133- nodes . forEach ( node => {
144+ nodes . forEach ( ( node ) => {
134145 let current : LexicalNode | null = node
135146
136147 // Walk up to find the nearest block-level parent (heading, paragraph, list item, etc.)
137148 while ( current ) {
138149 // Check if current node is a block-level node
139- if ( $isHeadingNode ( current ) ||
140- $isListItemNode ( current ) ||
141- current . getType ( ) === 'paragraph' ||
142- current . getType ( ) === 'quote' ) {
150+ if ( $isHeadingNode ( current ) || $isListItemNode ( current ) || current . getType ( ) === 'paragraph' || current . getType ( ) === 'quote' ) {
143151 if ( $isElementNode ( current ) ) {
144152 parentNodes . add ( current )
145153 }
@@ -159,19 +167,19 @@ export function getSelectionAsMarkdown(editor: LexicalEditor, _exportParams: Omi
159167 // Handle heading nodes
160168 const level = parseInt ( node . getTag ( ) . replace ( 'h' , '' ) )
161169 const children = node . getChildren ( )
162- const headingText = children . map ( child => nodeToMarkdown ( child ) ) . join ( '' )
170+ const headingText = children . map ( ( child ) => nodeToMarkdown ( child ) ) . join ( '' )
163171 return '#' . repeat ( level ) + ' ' + headingText + '\n\n'
164172 } else if ( $isListItemNode ( node ) ) {
165173 // Handle list item nodes
166174 const parent = node . getParent ( )
167175 const prefix = parent && $isListNode ( parent ) && parent . getListType ( ) === 'number' ? '1. ' : '- '
168176 const children = node . getChildren ( )
169- const itemText = children . map ( child => nodeToMarkdown ( child ) ) . join ( '' )
177+ const itemText = children . map ( ( child ) => nodeToMarkdown ( child ) ) . join ( '' )
170178 return prefix + itemText + '\n'
171179 } else if ( $isListNode ( node ) ) {
172180 // Handle list nodes
173181 const children = node . getChildren ( )
174- return children . map ( child => nodeToMarkdown ( child ) ) . join ( '' ) + '\n'
182+ return children . map ( ( child ) => nodeToMarkdown ( child ) ) . join ( '' ) + '\n'
175183 } else if ( $isTextNode ( node ) ) {
176184 let text = node . getTextContent ( )
177185 const format = node . getFormat ( )
@@ -202,7 +210,7 @@ export function getSelectionAsMarkdown(editor: LexicalEditor, _exportParams: Omi
202210 const url = node . getURL ( )
203211 const title = node . getTitle ( )
204212 const children = node . getChildren ( )
205- const linkText = children . map ( child => nodeToMarkdown ( child ) ) . join ( '' )
213+ const linkText = children . map ( ( child ) => nodeToMarkdown ( child ) ) . join ( '' )
206214
207215 if ( title ) {
208216 return `[${ linkText } ](${ url } "${ title } ")`
@@ -211,15 +219,15 @@ export function getSelectionAsMarkdown(editor: LexicalEditor, _exportParams: Omi
211219 } else if ( $isElementNode ( node ) ) {
212220 // For other element nodes, process their children
213221 const children = node . getChildren ( )
214- return children . map ( child => nodeToMarkdown ( child ) ) . join ( '' )
222+ return children . map ( ( child ) => nodeToMarkdown ( child ) ) . join ( '' )
215223 }
216224
217225 // Fallback: return text content
218226 return node . getTextContent ( )
219227 }
220228
221229 // Convert all selected nodes to markdown and concatenate
222- markdown = nodesToProcess . map ( node => nodeToMarkdown ( node ) ) . join ( '' )
230+ markdown = nodesToProcess . map ( ( node ) => nodeToMarkdown ( node ) ) . join ( '' )
223231 } )
224232
225233 return markdown . trim ( )
0 commit comments