@@ -44,7 +44,7 @@ function onPaste(event: ClipboardEvent) {
4444}
4545
4646function convertToMarkdown ( plaintext : string , walker : TreeWalker ) : string {
47- let currentNode = walker . firstChild ( ) as HTMLAnchorElement | HTMLElement | null
47+ let currentNode = walker . firstChild ( )
4848 let markdown = plaintext
4949 let markdownIgnoreBeforeIndex = 0
5050 let index = 0
@@ -54,12 +54,12 @@ function convertToMarkdown(plaintext: string, walker: TreeWalker): string {
5454 while ( currentNode && index < NODE_LIMIT ) {
5555 index ++
5656 const text = isLink ( currentNode )
57- ? ( currentNode as HTMLAnchorElement ) . textContent || ''
57+ ? currentNode . textContent || ''
5858 : ( currentNode . firstChild as Text ) ?. wholeText || ''
5959
6060 // No need to transform whitespace
6161 if ( isEmptyString ( text ) ) {
62- currentNode = walker . nextNode ( ) as HTMLAnchorElement | HTMLElement | null
62+ currentNode = walker . nextNode ( )
6363 continue
6464 }
6565
@@ -68,7 +68,7 @@ function convertToMarkdown(plaintext: string, walker: TreeWalker): string {
6868
6969 if ( markdownFoundIndex >= 0 ) {
7070 if ( isLink ( currentNode ) ) {
71- const markdownLink = linkify ( currentNode as HTMLAnchorElement )
71+ const markdownLink = linkify ( currentNode )
7272 // Transform 'example link plus more text' into 'example [link](example link) plus more text'
7373 // Method: 'example [link](example link) plus more text' = 'example ' + '[link](example link)' + ' plus more text'
7474 markdown =
@@ -79,7 +79,7 @@ function convertToMarkdown(plaintext: string, walker: TreeWalker): string {
7979 }
8080 }
8181
82- currentNode = walker . nextNode ( ) as HTMLAnchorElement | HTMLElement | null
82+ currentNode = walker . nextNode ( )
8383 }
8484
8585 // Unless we hit the node limit, we should have processed all nodes
@@ -90,8 +90,8 @@ function isEmptyString(text: string): boolean {
9090 return ! text || text ?. trim ( ) . length === 0
9191}
9292
93- function isLink ( node : HTMLElement ) : node is HTMLAnchorElement {
94- return node . tagName . toLowerCase ( ) === 'a' && node . hasAttribute ( 'href' )
93+ function isLink ( node : Node ) : node is HTMLAnchorElement {
94+ return ( node as HTMLElement ) . tagName ? .toLowerCase ( ) === 'a' && ( node as HTMLElement ) . hasAttribute ( 'href' )
9595}
9696
9797function hasHTML ( transfer : DataTransfer ) : boolean {
0 commit comments