mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-10-09 23:13:22 +08:00
添加quickcommand.markdownParse接口,可视化编排支持解析markdown
This commit is contained in:
@@ -83,8 +83,6 @@
|
||||
import { defineComponent } from "vue";
|
||||
import AISelector from "components/ai/AISelector.vue";
|
||||
import AIChatHistory from "components/ai/AIChatHistory.vue";
|
||||
import { marked } from "marked";
|
||||
import DOMPurify from "dompurify";
|
||||
|
||||
const quickcommandApi =
|
||||
require(`!raw-loader!plugins/monaco/types/quickcommand.api.d.ts`)
|
||||
@@ -229,19 +227,6 @@ export default defineComponent({
|
||||
this.autoUpdateCode = !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) {
|
||||
const languageMap = {
|
||||
quickcommand: "NodeJS",
|
||||
|
@@ -36,7 +36,6 @@
|
||||
|
||||
<script>
|
||||
import { defineComponent } from "vue";
|
||||
import { marked } from "marked";
|
||||
import DOMPurify from "dompurify";
|
||||
|
||||
export default defineComponent({
|
||||
@@ -74,7 +73,7 @@ export default defineComponent({
|
||||
},
|
||||
|
||||
getAssistantMsg(content) {
|
||||
const markedContent = marked(content.trim());
|
||||
const markedContent = quickcommand.markdownParse(content.trim());
|
||||
const processedContent = markedContent
|
||||
.replace("<p><think>", "<think><p>")
|
||||
.replace("</think></p>", "</p></think>")
|
||||
|
@@ -813,14 +813,14 @@ export const dataCommands = {
|
||||
width: 12,
|
||||
},
|
||||
{
|
||||
label: "CSS选择器",
|
||||
label: "CSS选择器(可选)",
|
||||
component: "VariableInput",
|
||||
icon: "css",
|
||||
placeholder: "例如:.class",
|
||||
width: 7,
|
||||
},
|
||||
{
|
||||
label: "属性",
|
||||
label: "属性(可选)",
|
||||
component: "VariableInput",
|
||||
icon: "colorize",
|
||||
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",
|
||||
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;
|
||||
|
||||
/**
|
||||
* 将给定的markdown字符串解析为html字符串
|
||||
*
|
||||
* @param markdown 需要解析的markdown文本
|
||||
* ```js
|
||||
* quickcommand.markdownParse("# 这是一个标题").then(html => {
|
||||
* console.log(html)
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
markdownParse(markdown: string): string;
|
||||
|
||||
/**
|
||||
* 下载文件,并返回文件的 Buffer,可选直接下载到指定路径,或者弹出对话框选择下载路径
|
||||
*
|
||||
|
Reference in New Issue
Block a user