This commit is contained in:
parent
5d154dc904
commit
2c1a5439e8
8 changed files with 132 additions and 31 deletions
41
package-lock.json
generated
41
package-lock.json
generated
|
|
@ -20,15 +20,18 @@
|
|||
"imapflow": "^1.0.171",
|
||||
"jsdom": "^29.0.1",
|
||||
"mailparser": "^3.9.6",
|
||||
"marked": "^18.2.0",
|
||||
"nodemailer": "^8.0.4",
|
||||
"pinia": "^3.0.2",
|
||||
"sanitize-html": "^2.17.2",
|
||||
"turndown": "^7.2.5",
|
||||
"vue": "^3.5.13",
|
||||
"vue-router": "^4.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/dompurify": "^3.2.0",
|
||||
"@types/nodemailer": "^8.0.0",
|
||||
"@types/turndown": "^5.0.6",
|
||||
"@vitejs/plugin-vue": "^5.2.3",
|
||||
"electron": "^35.1.2",
|
||||
"electron-builder": "^25.1.8",
|
||||
|
|
@ -1590,6 +1593,12 @@
|
|||
"integrity": "sha512-dlq6VExJReb8dhjj3a/yTigr3ncNwoFmL5Iy2ENtbDX03EmNeOEdZ+vsaGrj7RTuO+mB7L58II4LCsl4NpM8uw==",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@mixmark-io/domino": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@mixmark-io/domino/-/domino-2.2.0.tgz",
|
||||
"integrity": "sha512-Y28PR25bHXUg88kCV7nivXrP2Nj2RueZ3/l/jdx6J9f8J4nsEGcgX0Qe6lt7Pa+J79+kPiJU3LguR6O/6zrLOw==",
|
||||
"license": "BSD-2-Clause"
|
||||
},
|
||||
"node_modules/@npmcli/fs": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@npmcli/fs/-/fs-2.1.2.tgz",
|
||||
|
|
@ -2216,6 +2225,13 @@
|
|||
"license": "MIT",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/@types/turndown": {
|
||||
"version": "5.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/turndown/-/turndown-5.0.6.tgz",
|
||||
"integrity": "sha512-ru00MoyeeouE5BX4gRL+6m/BsDfbRayOskWqUvh7CLGW+UXxHQItqALa38kKnOiZPqJrtzJUgAC2+F0rL1S4Pg==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/verror": {
|
||||
"version": "1.10.11",
|
||||
"resolved": "https://registry.npmjs.org/@types/verror/-/verror-1.10.11.tgz",
|
||||
|
|
@ -6375,6 +6391,18 @@
|
|||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/marked": {
|
||||
"version": "18.2.0",
|
||||
"resolved": "https://registry.npmjs.org/marked/-/marked-18.2.0.tgz",
|
||||
"integrity": "sha512-KaeL+tAbtvI930q7HE2PN5lYXYdT8EiSmxHlN6F3rsfb57wd5mp5W5TLazpdj4inTQBJdgjYwbs40W/0VUGU+Q==",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"marked": "bin/marked.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 20"
|
||||
}
|
||||
},
|
||||
"node_modules/matcher": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/matcher/-/matcher-3.0.0.tgz",
|
||||
|
|
@ -8301,6 +8329,19 @@
|
|||
"utf8-byte-length": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/turndown": {
|
||||
"version": "7.2.5",
|
||||
"resolved": "https://registry.npmjs.org/turndown/-/turndown-7.2.5.tgz",
|
||||
"integrity": "sha512-EKZvCCFHh8sWttpAMs10U6niZFJ2cpz8LkCPlylxoG4JcHF50J7EHnnBW3AY1qXtUMu7kDjCp7dnggB1sIbqEQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@mixmark-io/domino": "^2.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18",
|
||||
"npm": ">=9"
|
||||
}
|
||||
},
|
||||
"node_modules/type-fest": {
|
||||
"version": "2.19.0",
|
||||
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz",
|
||||
|
|
|
|||
|
|
@ -32,15 +32,18 @@
|
|||
"imapflow": "^1.0.171",
|
||||
"jsdom": "^29.0.1",
|
||||
"mailparser": "^3.9.6",
|
||||
"marked": "^18.2.0",
|
||||
"nodemailer": "^8.0.4",
|
||||
"pinia": "^3.0.2",
|
||||
"sanitize-html": "^2.17.2",
|
||||
"turndown": "^7.2.5",
|
||||
"vue": "^3.5.13",
|
||||
"vue-router": "^4.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/dompurify": "^3.2.0",
|
||||
"@types/nodemailer": "^8.0.0",
|
||||
"@types/turndown": "^5.0.6",
|
||||
"@vitejs/plugin-vue": "^5.2.3",
|
||||
"electron": "^35.1.2",
|
||||
"electron-builder": "^25.1.8",
|
||||
|
|
|
|||
36
src/main/lib/html-to-markdown.ts
Normal file
36
src/main/lib/html-to-markdown.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import TurndownService from 'turndown'
|
||||
|
||||
const turndown = new TurndownService({
|
||||
headingStyle: 'atx',
|
||||
bulletListMarker: '-',
|
||||
codeBlockStyle: 'fenced',
|
||||
emDelimiter: '*'
|
||||
})
|
||||
turndown.remove(['style', 'script', 'head', 'title', 'meta'])
|
||||
|
||||
function decodeXmlText(raw: string): string {
|
||||
const cdata = raw.match(/^\s*<!\[CDATA\[([\s\S]*?)\]\]>\s*$/)
|
||||
if (cdata) return cdata[1]
|
||||
return raw
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, "'")
|
||||
.replace(/&#(\d+);/g, (_, n) => String.fromCodePoint(parseInt(n, 10)))
|
||||
.replace(/&#x([0-9a-f]+);/gi, (_, n) => String.fromCodePoint(parseInt(n, 16)))
|
||||
.replace(/&/g, '&')
|
||||
}
|
||||
|
||||
/**
|
||||
* Преобразует содержимое `<t:Body>` из EWS (XML-экранированный или CDATA HTML, либо plain text)
|
||||
* в Markdown.
|
||||
*/
|
||||
export function ewsBodyToMarkdown(rawBody: string, bodyType?: string): string {
|
||||
const content = decodeXmlText(rawBody)
|
||||
const isHtml = bodyType ? bodyType.toLowerCase() === 'html' : /<\/?[a-z][^>]*>/i.test(content)
|
||||
const markdown = isHtml ? turndown.turndown(content) : content
|
||||
return markdown
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/\n{3,}/g, '\n\n')
|
||||
.trim()
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ import http from 'node:http'
|
|||
import type { IncomingMessage } from 'node:http'
|
||||
import type { AccountConfig, ImapCredentials } from '@shared/types/account'
|
||||
import type { CalendarInfo, CalendarEvent, AttendeeInfo, AttendeeStatus } from '@shared/types/calendar'
|
||||
import { ewsBodyToMarkdown } from '../lib/html-to-markdown'
|
||||
import {
|
||||
buildNegotiateHeader,
|
||||
parseChallenge,
|
||||
|
|
@ -264,22 +265,11 @@ export class CalDavProvider {
|
|||
return distinguishedId === 'calendar' ? 'Календарь' : distinguishedId
|
||||
}
|
||||
|
||||
private static htmlToText(html: string): string {
|
||||
return html
|
||||
.replace(/<br\s*\/?>/gi, '\n')
|
||||
.replace(/<\/p\s*>/gi, '\n\n')
|
||||
.replace(/<\/div\s*>/gi, '\n')
|
||||
.replace(/<\/li\s*>/gi, '\n')
|
||||
.replace(/<\/tr\s*>/gi, '\n')
|
||||
.replace(/<[^>]+>/g, '')
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/&#(\d+);/g, (_, n) => String.fromCharCode(parseInt(n, 10)))
|
||||
.replace(/\n{3,}/g, '\n\n')
|
||||
.trim()
|
||||
private static parseEwsBody(block: string): string | undefined {
|
||||
const r = block.match(/<t:Body(?:\s([^>]*))?>([\s\S]*?)<\/t:Body>/)
|
||||
if (!r) return undefined
|
||||
const bodyType = r[1]?.match(/BodyType="([^"]+)"/)?.[1]
|
||||
return ewsBodyToMarkdown(r[2], bodyType) || undefined
|
||||
}
|
||||
|
||||
private async enrichWithAttendees(events: CalendarEvent[]): Promise<void> {
|
||||
|
|
@ -311,8 +301,7 @@ export class CalDavProvider {
|
|||
if (target) {
|
||||
target.attendees = this.parseAttendeesList(itemBlock)
|
||||
if (!target.description) {
|
||||
const body = itemBlock.match(/<t:Body(?:\s[^>]*)?>([\s\S]*?)<\/t:Body>/)
|
||||
target.description = (body && CalDavProvider.htmlToText(body[1])) || undefined
|
||||
target.description = CalDavProvider.parseEwsBody(itemBlock)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -379,12 +368,6 @@ export class CalDavProvider {
|
|||
const r = block.match(new RegExp(`<t:${tag}(?:\\s[^>]*)?>([\\s\\S]*?)<\\/t:${tag}>`))
|
||||
return r ? r[1].replace(/<[^>]+>/g, '').trim() : ''
|
||||
}
|
||||
const getBody = (): string | undefined => {
|
||||
const r = block.match(/<t:Body(?:\s[^>]*)?>([\s\S]*?)<\/t:Body>/)
|
||||
if (!r) return undefined
|
||||
const text = CalDavProvider.htmlToText(r[1])
|
||||
return text || undefined
|
||||
}
|
||||
const idM = block.match(/<t:ItemId\s+Id="([^"]+)"/)
|
||||
if (!idM) continue
|
||||
const startStr = get('Start')
|
||||
|
|
@ -421,7 +404,7 @@ export class CalDavProvider {
|
|||
end: end.toISOString(),
|
||||
isAllDay,
|
||||
location: get('Location') || undefined,
|
||||
description: getBody(),
|
||||
description: CalDavProvider.parseEwsBody(block),
|
||||
organizer,
|
||||
attendees: [],
|
||||
status: fbStatus === 'tentative' ? 'tentative' : 'confirmed'
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import { computed, ref } from 'vue'
|
||||
import { format } from 'date-fns'
|
||||
import { ru } from 'date-fns/locale'
|
||||
import { renderMarkdown } from '../../composables/useMarkdown'
|
||||
import type { CalendarEvent, AttendeeInfo } from '@shared/types/calendar'
|
||||
import AppIcon from '../AppIcon.vue'
|
||||
import { useIpc } from '../../composables/useIpc'
|
||||
|
|
@ -276,7 +277,8 @@ async function copyEmail(email: string) {
|
|||
|
||||
<!-- Description -->
|
||||
<div v-if="event.description" class="card desc-card">
|
||||
<p class="desc-text selectable">{{ event.description }}</p>
|
||||
<!-- eslint-disable-next-line vue/no-v-html -->
|
||||
<div class="desc-text markdown selectable" v-html="renderMarkdown(event.description)" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
@ -554,9 +556,21 @@ async function copyEmail(email: string) {
|
|||
|
||||
.desc-card { padding:16px }
|
||||
.desc-text {
|
||||
font-size:13px; color:rgba(255,255,255,0.52); white-space:pre-wrap;
|
||||
font-size:13px; color:rgba(255,255,255,0.52);
|
||||
line-height:1.7; margin:0; word-break:break-word;
|
||||
}
|
||||
.desc-text :deep(> :first-child) { margin-top:0 }
|
||||
.desc-text :deep(> :last-child) { margin-bottom:0 }
|
||||
.desc-text :deep(p), .desc-text :deep(ul), .desc-text :deep(ol), .desc-text :deep(pre) { margin:0 0 8px }
|
||||
.desc-text :deep(ul), .desc-text :deep(ol) { padding-left:20px }
|
||||
.desc-text :deep(h1), .desc-text :deep(h2), .desc-text :deep(h3), .desc-text :deep(h4) { font-size:13px; margin:8px 0 4px; color:rgba(255,255,255,0.7) }
|
||||
.desc-text :deep(a) { color:var(--accent); text-decoration:underline }
|
||||
.desc-text :deep(code) { font-family:monospace; background:rgba(255,255,255,0.08); padding:0 4px; border-radius:4px }
|
||||
.desc-text :deep(pre) { overflow-x:auto }
|
||||
.desc-text :deep(blockquote) { margin:0 0 8px; padding-left:10px; border-left:2px solid rgba(255,255,255,0.2) }
|
||||
.desc-text :deep(table) { border-collapse:collapse }
|
||||
.desc-text :deep(td), .desc-text :deep(th) { border:1px solid rgba(255,255,255,0.15); padding:2px 6px }
|
||||
.desc-text :deep(img) { max-width:100% }
|
||||
|
||||
/* ── Material 3 ── */
|
||||
/* Центрированное модальное окно → dialog-паттерн, extra-large shape, elevation-3 */
|
||||
|
|
|
|||
15
src/renderer/src/composables/useMarkdown.ts
Normal file
15
src/renderer/src/composables/useMarkdown.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import DOMPurify from 'dompurify'
|
||||
import { marked } from 'marked'
|
||||
|
||||
DOMPurify.addHook('afterSanitizeAttributes', (node) => {
|
||||
if (node.tagName === 'A') {
|
||||
node.setAttribute('target', '_blank')
|
||||
node.setAttribute('rel', 'noopener noreferrer')
|
||||
}
|
||||
})
|
||||
|
||||
/** Рендерит Markdown в безопасный HTML (для `v-html`). */
|
||||
export function renderMarkdown(markdown: string): string {
|
||||
const html = marked.parse(markdown, { async: false, gfm: true, breaks: true })
|
||||
return DOMPurify.sanitize(html, { USE_PROFILES: { html: true } })
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ import { ref, onMounted, onUnmounted, watch, nextTick } from 'vue'
|
|||
import { format } from 'date-fns'
|
||||
import { useIpc } from '../composables/useIpc'
|
||||
import { useSettingsStore } from '../stores/settings.store'
|
||||
import { renderMarkdown } from '../composables/useMarkdown'
|
||||
import AppIcon from '../components/AppIcon.vue'
|
||||
import type { MeetingReminder } from '@shared/types/calendar'
|
||||
|
||||
|
|
@ -86,9 +87,12 @@ function open(key: string): void { void invoke('reminder:open', { key }) }
|
|||
<span>{{ reminder.event.location }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="reminder.event.description" class="card-description">
|
||||
{{ reminder.event.description }}
|
||||
</div>
|
||||
<!-- eslint-disable-next-line vue/no-v-html -->
|
||||
<div
|
||||
v-if="reminder.event.description"
|
||||
class="card-description markdown"
|
||||
v-html="renderMarkdown(reminder.event.description)"
|
||||
/>
|
||||
|
||||
<div class="card-actions">
|
||||
<button v-if="reminder.joinUrl" class="action-btn primary" @click="join(reminder.key)">
|
||||
|
|
@ -208,7 +212,6 @@ function open(key: string): void { void invoke('reminder:open', { key }) }
|
|||
.card-description {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
white-space: pre-line;
|
||||
word-break: break-word;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 4;
|
||||
|
|
@ -216,6 +219,11 @@ function open(key: string): void { void invoke('reminder:open', { key }) }
|
|||
overflow: hidden;
|
||||
}
|
||||
|
||||
.card-description :deep(*) { margin: 0; padding: 0; font-size: inherit; }
|
||||
.card-description :deep(ul),
|
||||
.card-description :deep(ol) { padding-left: 16px; }
|
||||
.card-description :deep(a) { color: var(--accent); }
|
||||
|
||||
.card-actions {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ export interface CalendarEvent {
|
|||
end: string // ISO 8601
|
||||
isAllDay: boolean
|
||||
location?: string
|
||||
/** Описание в формате Markdown */
|
||||
description?: string
|
||||
organizer?: string
|
||||
attendees: AttendeeInfo[]
|
||||
|
|
|
|||
Loading…
Reference in a new issue