Skip to content

Commit 3a7ea4b

Browse files
committed
refactor: adjust types
1 parent a1e4719 commit 3a7ea4b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/paste-markdown-html.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function onPaste(event: ClipboardEvent) {
4444
}
4545

4646
function 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

9797
function hasHTML(transfer: DataTransfer): boolean {

0 commit comments

Comments
 (0)