From 6bcf8f89f050828971acf4817a71b96489bd8073 Mon Sep 17 00:00:00 2001 From: zhengyi Date: Sun, 14 Apr 2024 10:43:02 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E2=9C=A8=20Add=20feature=20"use=20first=20?= =?UTF-8?q?h1=20as=20title"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix https://github.com/justice2001/halo-plugin-vditor/issues/33 Fix https://git.mczhengyi.top/zhengyi/halo-plugin-vditor/issues/74 --- CHANGELOG.md | 4 ++ build.gradle | 2 +- console/src/model/DebugPanel.vue | 8 ++- console/src/utils/config-utils.ts | 2 + console/src/utils/vditor-utils.ts | 8 ++- console/src/views/VditorMde.vue | 55 ++++++++++++++++++--- gradle.properties | 2 +- src/main/resources/extensions/settings.yaml | 5 ++ src/main/resources/plugin.yaml | 2 +- 9 files changed, 77 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9533276..9c21e3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 更新记录 +### v1.7.0 + +- ✨ 添加`使用第一个h1作为标题`的功能 + ### v1.6.2 - ⬆️ 升级Vditor版本至3.10.2 diff --git a/build.gradle b/build.gradle index 897183a..c731c45 100644 --- a/build.gradle +++ b/build.gradle @@ -41,7 +41,7 @@ build { } halo { - version = '2.12' + version = '2.14.0-rc.1' superAdminUsername = 'admin' superAdminPassword = 'admin' externalUrl = 'http://localhost:8090' diff --git a/console/src/model/DebugPanel.vue b/console/src/model/DebugPanel.vue index 930e6e6..7243cdb 100644 --- a/console/src/model/DebugPanel.vue +++ b/console/src/model/DebugPanel.vue @@ -2,8 +2,9 @@
- + DEBUG
+ Get Raw Get HTML Get Vditor Options @@ -36,6 +37,11 @@ const props = defineProps<{ cursor: Range | undefined; }>(); +const getRaw = () => { + if (!props.vditor) return; + console.log("RAW: ", props.vditor?.getValue()); +}; + const getHTML = () => { if (!props.vditor) return; console.log("HTML", renderHTML(props.vditor)); diff --git a/console/src/utils/config-utils.ts b/console/src/utils/config-utils.ts index 900351d..a43f4e4 100644 --- a/console/src/utils/config-utils.ts +++ b/console/src/utils/config-utils.ts @@ -7,6 +7,7 @@ export declare type EditorConfig = { enableQuickInsert: boolean; quickInsertUrl: []; disableHTMLBlockPreview: boolean; + firstH1AsTitle: boolean; }; extension: { allowImageType: string; @@ -25,6 +26,7 @@ export const defaultEditorConfig: EditorConfig = { enableQuickInsert: false, quickInsertUrl: [], disableHTMLBlockPreview: false, + firstH1AsTitle: false, }, extension: { allowImageType: "png,jpg,jpeg,bmp,gif,webp,svg", diff --git a/console/src/utils/vditor-utils.ts b/console/src/utils/vditor-utils.ts index b150be1..45b28a8 100644 --- a/console/src/utils/vditor-utils.ts +++ b/console/src/utils/vditor-utils.ts @@ -7,6 +7,7 @@ import drive from "@/schema/drive"; import gallery from "@/schema/gallery"; import { addScript, addStyleSheet } from "@/utils/dom-utils"; import type Vditor from "vditor"; +import type {EditorConfig} from "@/utils/config-utils"; declare const HaloJs: { renderHalo: (content: string, cdn: string) => string; @@ -235,9 +236,10 @@ function getCustomRenders(options: Options): * @param vditor vditor * @returns html */ -export function renderHTML(vditor: Vditor): string { +export function renderHTML(vditor: Vditor, config: EditorConfig): string { let value = vditor.getHTML(); const customRenders = vditor.vditor.options.customRenders; + // FIXME 此部分逻辑有大问题! customRenders?.forEach((render) => { const reg = new RegExp( `
(.*?)
`, @@ -245,5 +247,9 @@ export function renderHTML(vditor: Vditor): string { ); value = value.replace(reg, '
$1
'); }); + // Remove H1 Title When start with "h1" + if (config.basic.firstH1AsTitle && value.startsWith("(.*?)<\/h1>/, ""); + } return value; } diff --git a/console/src/views/VditorMde.vue b/console/src/views/VditorMde.vue index 3e8cd12..e149f84 100644 --- a/console/src/views/VditorMde.vue +++ b/console/src/views/VditorMde.vue @@ -1,6 +1,6 @@