refactor(renderer): configure the Markdown image renderer at startup
renderMarkdown ran the marked configuration on every call and leaned on a module-level flag to make that cheap. It belongs next to the custom element registration, which already runs once, before anything renders. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
1124758b6b
commit
5f7f6d7cd5
@@ -7,6 +7,7 @@ import { commitInitialData, fetchInitialData } from './data.js';
|
|||||||
import { noteSessionUpdated, sessionLiveState } from './session-live.mjs';
|
import { noteSessionUpdated, sessionLiveState } from './session-live.mjs';
|
||||||
import { createGlobalDataRefreshCoordinator } from './session-global-refresh.mjs';
|
import { createGlobalDataRefreshCoordinator } from './session-global-refresh.mjs';
|
||||||
import { registerSessionImageElement } from './session-image-element.js';
|
import { registerSessionImageElement } from './session-image-element.js';
|
||||||
|
import { configureMarkdownImages } from './markdown-image-renderer.js';
|
||||||
import { installFileReferenceHandler } from './file-references.mjs';
|
import { installFileReferenceHandler } from './file-references.mjs';
|
||||||
|
|
||||||
// Import shared renderer CSS globally
|
// Import shared renderer CSS globally
|
||||||
@@ -17,6 +18,8 @@ import '../styles/list.css';
|
|||||||
import '../styles/detail.css';
|
import '../styles/detail.css';
|
||||||
|
|
||||||
registerSessionImageElement();
|
registerSessionImageElement();
|
||||||
|
// marked is loaded globally via CDN in index.html, ahead of this module.
|
||||||
|
configureMarkdownImages(window.marked);
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
// Pure helpers with no side-effects on global state (except formatProjectLabel which reads store).
|
// Pure helpers with no side-effects on global state (except formatProjectLabel which reads store).
|
||||||
|
|
||||||
import { state } from './store.js';
|
import { state } from './store.js';
|
||||||
import { configureMarkdownImages } from './markdown-image-renderer.js';
|
|
||||||
import { markFileReferences, mayContainFileReference } from './file-references.mjs';
|
import { markFileReferences, mayContainFileReference } from './file-references.mjs';
|
||||||
|
|
||||||
// --- Time / formatting ---
|
// --- Time / formatting ---
|
||||||
@@ -96,8 +95,7 @@ export function highlightTextNodes(rootEl, query) {
|
|||||||
|
|
||||||
export function renderMarkdown(text, opts = {}) {
|
export function renderMarkdown(text, opts = {}) {
|
||||||
if (text == null) return '';
|
if (text == null) return '';
|
||||||
// marked is loaded globally via CDN in index.html
|
// marked is loaded globally via CDN in index.html and configured at startup.
|
||||||
configureMarkdownImages(window.marked);
|
|
||||||
const html = sanitizeMarkdown(window.marked.parse(text));
|
const html = sanitizeMarkdown(window.marked.parse(text));
|
||||||
const cls = opts.variant === 'msg' ? 'markdown-msg'
|
const cls = opts.variant === 'msg' ? 'markdown-msg'
|
||||||
: opts.variant === 'compact' ? 'markdown-compact'
|
: opts.variant === 'compact' ? 'markdown-compact'
|
||||||
|
|||||||
Reference in New Issue
Block a user