mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-12 16:54:06 +08:00
添加quickcommand.markdownParse接口,可视化编排支持解析markdown
This commit is contained in:
parent
196d54a993
commit
60ac9fbc81
18
package-lock.json
generated
18
package-lock.json
generated
@ -12,7 +12,6 @@
|
|||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
"croner": "^4.3.9",
|
"croner": "^4.3.9",
|
||||||
"dompurify": "^3.2.4",
|
"dompurify": "^3.2.4",
|
||||||
"marked": "^15.0.7",
|
|
||||||
"monaco-editor": "^0.33.0",
|
"monaco-editor": "^0.33.0",
|
||||||
"monaco-editor-webpack-plugin": "^7.0.1",
|
"monaco-editor-webpack-plugin": "^7.0.1",
|
||||||
"picture-compressor": "^1.1.0",
|
"picture-compressor": "^1.1.0",
|
||||||
@ -7024,18 +7023,6 @@
|
|||||||
"sourcemap-codec": "^1.4.8"
|
"sourcemap-codec": "^1.4.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/marked": {
|
|
||||||
"version": "15.0.7",
|
|
||||||
"resolved": "https://registry.npmmirror.com/marked/-/marked-15.0.7.tgz",
|
|
||||||
"integrity": "sha512-dgLIeKGLx5FwziAnsk4ONoGwHwGPJzselimvlVskE9XLN4Orv9u2VA3GWw/lYUqjfA0rUT/6fqKwfZJapP9BEg==",
|
|
||||||
"license": "MIT",
|
|
||||||
"bin": {
|
|
||||||
"marked": "bin/marked.js"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/math-intrinsics": {
|
"node_modules/math-intrinsics": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||||
@ -16309,11 +16296,6 @@
|
|||||||
"sourcemap-codec": "^1.4.8"
|
"sourcemap-codec": "^1.4.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"marked": {
|
|
||||||
"version": "15.0.7",
|
|
||||||
"resolved": "https://registry.npmmirror.com/marked/-/marked-15.0.7.tgz",
|
|
||||||
"integrity": "sha512-dgLIeKGLx5FwziAnsk4ONoGwHwGPJzselimvlVskE9XLN4Orv9u2VA3GWw/lYUqjfA0rUT/6fqKwfZJapP9BEg=="
|
|
||||||
},
|
|
||||||
"math-intrinsics": {
|
"math-intrinsics": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
"croner": "^4.3.9",
|
"croner": "^4.3.9",
|
||||||
"dompurify": "^3.2.4",
|
"dompurify": "^3.2.4",
|
||||||
"marked": "^15.0.7",
|
|
||||||
"monaco-editor": "^0.33.0",
|
"monaco-editor": "^0.33.0",
|
||||||
"monaco-editor-webpack-plugin": "^7.0.1",
|
"monaco-editor-webpack-plugin": "^7.0.1",
|
||||||
"picture-compressor": "^1.1.0",
|
"picture-compressor": "^1.1.0",
|
||||||
|
@ -5,6 +5,7 @@ const kill = require("tree-kill");
|
|||||||
const iconv = require("iconv-lite");
|
const iconv = require("iconv-lite");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
|
const marked = require("marked");
|
||||||
const { chat, getModels } = require("./ai");
|
const { chat, getModels } = require("./ai");
|
||||||
|
|
||||||
window.getModelsFromAiApi = getModels;
|
window.getModelsFromAiApi = getModels;
|
||||||
@ -84,6 +85,11 @@ const quickcommand = {
|
|||||||
return new DOMParser().parseFromString(html, "text/html");
|
return new DOMParser().parseFromString(html, "text/html");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// markdown 解析
|
||||||
|
markdownParse: function (markdown) {
|
||||||
|
return marked.parse(markdown);
|
||||||
|
},
|
||||||
|
|
||||||
// 下载文件
|
// 下载文件
|
||||||
downloadFile: function (url, file) {
|
downloadFile: function (url, file) {
|
||||||
return new Promise((reslove, reject) => {
|
return new Promise((reslove, reject) => {
|
||||||
|
18
plugin/package-lock.json
generated
18
plugin/package-lock.json
generated
@ -10,6 +10,7 @@
|
|||||||
"crypto-js": "^4.2.0",
|
"crypto-js": "^4.2.0",
|
||||||
"exif-reader": "^2.0.1",
|
"exif-reader": "^2.0.1",
|
||||||
"iconv-lite": "^0.6.3",
|
"iconv-lite": "^0.6.3",
|
||||||
|
"marked": "^15.0.7",
|
||||||
"node-forge": "^1.3.1",
|
"node-forge": "^1.3.1",
|
||||||
"png2icons": "^2.0.1",
|
"png2icons": "^2.0.1",
|
||||||
"ses": "^1.10.0",
|
"ses": "^1.10.0",
|
||||||
@ -141,6 +142,18 @@
|
|||||||
"integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==",
|
"integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/marked": {
|
||||||
|
"version": "15.0.7",
|
||||||
|
"resolved": "https://registry.npmmirror.com/marked/-/marked-15.0.7.tgz",
|
||||||
|
"integrity": "sha512-dgLIeKGLx5FwziAnsk4ONoGwHwGPJzselimvlVskE9XLN4Orv9u2VA3GWw/lYUqjfA0rUT/6fqKwfZJapP9BEg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"marked": "bin/marked.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 18"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/mime-db": {
|
"node_modules/mime-db": {
|
||||||
"version": "1.52.0",
|
"version": "1.52.0",
|
||||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||||
@ -324,6 +337,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz",
|
||||||
"integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A=="
|
"integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A=="
|
||||||
},
|
},
|
||||||
|
"marked": {
|
||||||
|
"version": "15.0.7",
|
||||||
|
"resolved": "https://registry.npmmirror.com/marked/-/marked-15.0.7.tgz",
|
||||||
|
"integrity": "sha512-dgLIeKGLx5FwziAnsk4ONoGwHwGPJzselimvlVskE9XLN4Orv9u2VA3GWw/lYUqjfA0rUT/6fqKwfZJapP9BEg=="
|
||||||
|
},
|
||||||
"mime-db": {
|
"mime-db": {
|
||||||
"version": "1.52.0",
|
"version": "1.52.0",
|
||||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
"crypto-js": "^4.2.0",
|
"crypto-js": "^4.2.0",
|
||||||
"exif-reader": "^2.0.1",
|
"exif-reader": "^2.0.1",
|
||||||
"iconv-lite": "^0.6.3",
|
"iconv-lite": "^0.6.3",
|
||||||
|
"marked": "^15.0.7",
|
||||||
"node-forge": "^1.3.1",
|
"node-forge": "^1.3.1",
|
||||||
"png2icons": "^2.0.1",
|
"png2icons": "^2.0.1",
|
||||||
"ses": "^1.10.0",
|
"ses": "^1.10.0",
|
||||||
|
@ -11,6 +11,7 @@ const http = require("http");
|
|||||||
const https = require("https");
|
const https = require("https");
|
||||||
const url = require("url");
|
const url = require("url");
|
||||||
const crypto = require("crypto");
|
const crypto = require("crypto");
|
||||||
|
|
||||||
require("ses");
|
require("ses");
|
||||||
const md5 = (input) => {
|
const md5 = (input) => {
|
||||||
return crypto.createHash("md5").update(input, "utf8").digest("hex");
|
return crypto.createHash("md5").update(input, "utf8").digest("hex");
|
||||||
|
@ -83,8 +83,6 @@
|
|||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
import AISelector from "components/ai/AISelector.vue";
|
import AISelector from "components/ai/AISelector.vue";
|
||||||
import AIChatHistory from "components/ai/AIChatHistory.vue";
|
import AIChatHistory from "components/ai/AIChatHistory.vue";
|
||||||
import { marked } from "marked";
|
|
||||||
import DOMPurify from "dompurify";
|
|
||||||
|
|
||||||
const quickcommandApi =
|
const quickcommandApi =
|
||||||
require(`!raw-loader!plugins/monaco/types/quickcommand.api.d.ts`)
|
require(`!raw-loader!plugins/monaco/types/quickcommand.api.d.ts`)
|
||||||
@ -229,19 +227,6 @@ export default defineComponent({
|
|||||||
this.autoUpdateCode = !this.autoUpdateCode;
|
this.autoUpdateCode = !this.autoUpdateCode;
|
||||||
localStorage.setItem("ai_auto_update", this.autoUpdateCode);
|
localStorage.setItem("ai_auto_update", this.autoUpdateCode);
|
||||||
},
|
},
|
||||||
getTrimContent(content) {
|
|
||||||
const markedContent = marked(content.trim());
|
|
||||||
// 解决think标签被错误地包裹在<p>标签中
|
|
||||||
const processedContent = markedContent
|
|
||||||
.replace("<p><think>", "<think><p>")
|
|
||||||
.replace("</think></p>", "</p></think>")
|
|
||||||
// 去除空的think标签
|
|
||||||
.replace("<think>\n\n</think>", "");
|
|
||||||
const purifiedContent = DOMPurify.sanitize(processedContent, {
|
|
||||||
ADD_TAGS: ["think"],
|
|
||||||
});
|
|
||||||
return purifiedContent;
|
|
||||||
},
|
|
||||||
getRolePrompt(language) {
|
getRolePrompt(language) {
|
||||||
const languageMap = {
|
const languageMap = {
|
||||||
quickcommand: "NodeJS",
|
quickcommand: "NodeJS",
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
import { marked } from "marked";
|
|
||||||
import DOMPurify from "dompurify";
|
import DOMPurify from "dompurify";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@ -74,7 +73,7 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getAssistantMsg(content) {
|
getAssistantMsg(content) {
|
||||||
const markedContent = marked(content.trim());
|
const markedContent = quickcommand.markdownParse(content.trim());
|
||||||
const processedContent = markedContent
|
const processedContent = markedContent
|
||||||
.replace("<p><think>", "<think><p>")
|
.replace("<p><think>", "<think><p>")
|
||||||
.replace("</think></p>", "</p></think>")
|
.replace("</think></p>", "</p></think>")
|
||||||
|
@ -813,14 +813,14 @@ export const dataCommands = {
|
|||||||
width: 12,
|
width: 12,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "CSS选择器",
|
label: "CSS选择器(可选)",
|
||||||
component: "VariableInput",
|
component: "VariableInput",
|
||||||
icon: "css",
|
icon: "css",
|
||||||
placeholder: "例如:.class",
|
placeholder: "例如:.class",
|
||||||
width: 7,
|
width: 7,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "属性",
|
label: "属性(可选)",
|
||||||
component: "VariableInput",
|
component: "VariableInput",
|
||||||
icon: "colorize",
|
icon: "colorize",
|
||||||
options: {
|
options: {
|
||||||
@ -837,6 +837,25 @@ export const dataCommands = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
value: "quickcommand.markdownParse",
|
||||||
|
label: "Markdown解析",
|
||||||
|
icon: "file_download",
|
||||||
|
config: [
|
||||||
|
{
|
||||||
|
label: "要解析的Markdown",
|
||||||
|
component: "VariableInput",
|
||||||
|
icon: "file_download",
|
||||||
|
width: 12,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
outputs: [
|
||||||
|
{
|
||||||
|
label: "解析后的HTML",
|
||||||
|
suggestName: "parsedHtml",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
value: "JSON.stringify",
|
value: "JSON.stringify",
|
||||||
label: "JSON处理",
|
label: "JSON处理",
|
||||||
|
12
src/plugins/monaco/types/quickcommand.api.d.ts
vendored
12
src/plugins/monaco/types/quickcommand.api.d.ts
vendored
@ -260,6 +260,18 @@ interface quickcommandApi {
|
|||||||
*/
|
*/
|
||||||
htmlParse(html: string): object;
|
htmlParse(html: string): object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将给定的markdown字符串解析为html字符串
|
||||||
|
*
|
||||||
|
* @param markdown 需要解析的markdown文本
|
||||||
|
* ```js
|
||||||
|
* quickcommand.markdownParse("# 这是一个标题").then(html => {
|
||||||
|
* console.log(html)
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
markdownParse(markdown: string): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载文件,并返回文件的 Buffer,可选直接下载到指定路径,或者弹出对话框选择下载路径
|
* 下载文件,并返回文件的 Buffer,可选直接下载到指定路径,或者弹出对话框选择下载路径
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user