added imagex to send images along messages
All checks were successful
Build OCI Images / build (push) Successful in 2m57s

This commit is contained in:
Rose 2024-09-11 13:19:35 -04:00
parent 0e14cca2eb
commit dc12389cf3
No known key found for this signature in database
10 changed files with 1330 additions and 357 deletions

View file

@ -0,0 +1,4 @@
{
"$schema": "https://biomejs.dev/schemas/1.6.4/schema.json",
"extends": ["@datamine/config/biome"]
}

View file

@ -0,0 +1,34 @@
{
"name": "@datamine/imagex",
"packageManager": "yarn@4.1.1",
"private": true,
"type": "module",
"main": "./dist/main.js",
"module": "./dist/main.js",
"types": "./dist/main.d.ts",
"exports": {
"import": {
"types": "./dist/main.d.ts",
"default": "./dist/main.js"
}
},
"devDependencies": {
"@biomejs/biome": "1.6.4",
"@datamine/config": "workspace:*",
"@types/node": "20.12.7",
"pkgroll": "2.0.2",
"tsx": "4.7.2",
"typescript": "5.4.5"
},
"scripts": {
"lint": "biome ci ./src/**/*",
"build": "pkgroll"
},
"dependencies": {
"rehype-parse": "^9.0.0",
"remark-gfm": "^4.0.0",
"remark-parse": "^11.0.0",
"unified": "^11.0.5",
"unist-util-visit": "^5.0.0"
}
}

View file

@ -0,0 +1,24 @@
import rehypeParse from "rehype-parse";
import remarkGfm from "remark-gfm";
import remarkParse from "remark-parse";
import { unified } from "unified";
import { visit } from "unist-util-visit";
export function extract(md: string) {
const images: string[] = [];
const mdast = unified().use(remarkParse).use(remarkGfm).parse(md);
visit(mdast, "image", (node) => {
images.push(node.url);
});
visit(mdast, "html", (node) => {
const hast = unified()
.use(rehypeParse, { fragment: true })
.parse(node.value);
visit(hast, "element", (node) => {
if (node.tagName === "img") {
images.push(node.properties?.src as string);
}
});
});
return images;
}

View file

@ -0,0 +1,5 @@
{
"extends": "@datamine/config/typescript",
"exclude": ["node_modules"],
"include": ["src"]
}