✨ added imagex to send images along messages
All checks were successful
Build OCI Images / build (push) Successful in 2m57s
All checks were successful
Build OCI Images / build (push) Successful in 2m57s
This commit is contained in:
parent
0e14cca2eb
commit
dc12389cf3
10 changed files with 1330 additions and 357 deletions
4
packages/imagex/biome.json
Normal file
4
packages/imagex/biome.json
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://biomejs.dev/schemas/1.6.4/schema.json",
|
||||
"extends": ["@datamine/config/biome"]
|
||||
}
|
||||
34
packages/imagex/package.json
Normal file
34
packages/imagex/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
24
packages/imagex/src/main.ts
Normal file
24
packages/imagex/src/main.ts
Normal 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;
|
||||
}
|
||||
5
packages/imagex/tsconfig.json
Normal file
5
packages/imagex/tsconfig.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"extends": "@datamine/config/typescript",
|
||||
"exclude": ["node_modules"],
|
||||
"include": ["src"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue