-
Notifications
You must be signed in to change notification settings - Fork 0
修复 Mermaid 预览生命周期并发布图片预览 v1.2.9 #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,7 @@ import { | |
| import { createMermaidFullscreenButton } from "../mermaid/mermaidFullscreen"; | ||
| import { parseMermaidSvg } from "../mermaid/mermaidSvg"; | ||
| import { formatCodeFenceLanguageLabel } from "../codeFencePresentation"; | ||
| import { openImagePreview } from "../imagePreview"; | ||
|
|
||
| const IMAGE_EXTENSIONS = /\.(png|jpe?g|gif|svg|webp|bmp|ico|avif)([?#].*)?$/i; | ||
| const PDF_EXTENSION = /\.pdf([?#].*)?$/i; | ||
|
|
@@ -483,6 +484,20 @@ class ImageWidget extends WidgetType { | |
| img.draggable = false; | ||
| img.loading = "lazy"; | ||
| img.decoding = "async"; | ||
| img.tabIndex = 0; | ||
| img.setAttribute("role", "button"); | ||
| img.setAttribute("aria-label", translate("Open image preview")); | ||
| img.addEventListener("click", (event) => { | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| openImagePreview(this.src, this.alt); | ||
| }); | ||
|
Comment on lines
+490
to
+494
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For linked-image syntax such as Useful? React with 👍 / 👎. |
||
| img.addEventListener("keydown", (event) => { | ||
| if (event.key !== "Enter" && event.key !== " ") return; | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| openImagePreview(this.src, this.alt); | ||
| }); | ||
| if (this.title) img.title = this.title; | ||
| if (this.width) { | ||
| img.style.width = `${this.width}px`; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| export const OPEN_IMAGE_PREVIEW_EVENT = "bifrostwrite:open-image-preview"; | ||
|
|
||
| export interface OpenImagePreviewPayload { | ||
| src: string; | ||
| alt: string; | ||
| } | ||
|
|
||
| export function openImagePreview(src: string, alt = "") { | ||
| if (!src.trim()) return; | ||
|
|
||
| window.dispatchEvent( | ||
| new CustomEvent<OpenImagePreviewPayload>(OPEN_IMAGE_PREVIEW_EVENT, { | ||
| detail: { src, alt }, | ||
| }), | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Markdown images with meaningful alt text, this explicit generic
aria-labeloverrides the native accessible name supplied byimg.alt, so every rendered image is announced only as “Open image preview” and screen-reader users lose the image's description. Includethis.altin the button label (with a sensible fallback when it is empty) instead of replacing it entirely.Useful? React with 👍 / 👎.