feat: media picker and image removal
This commit is contained in:
1 parent
008b0dfbb9
commit
b3793d5dbb
54 files changed
+3769
-1412
No files matched your search
@@ -0,0 +1,13 @@
|
||||
const IMAGE_ID_SELECTOR = 'img[data-image-id]'
|
||||
const IMAGE_ID_ATTRIBUTE = 'data-image-id'
|
||||
|
||||
export function bodyImageCount(html: string): number {
|
||||
return new DOMParser().parseFromString(html, 'text/html').querySelectorAll('img').length
|
||||
}
|
||||
|
||||
export function bodyImageIds(html: string): number[] {
|
||||
const document = new DOMParser().parseFromString(html, 'text/html')
|
||||
return Array.from(document.querySelectorAll(IMAGE_ID_SELECTOR))
|
||||
.map((image) => Number.parseInt(image.getAttribute(IMAGE_ID_ATTRIBUTE) ?? '', 10))
|
||||
.filter((id) => !Number.isNaN(id))
|
||||
}
|
||||
Reference in new issue
Block a user