Merge ea773421e8 into 58062860af
This commit is contained in:
commit
b9b17db643
Binary file not shown.
|
|
@ -7,15 +7,18 @@
|
||||||
import remarkRehype from 'remark-rehype';
|
import remarkRehype from 'remark-rehype';
|
||||||
import rehypeKatex from 'rehype-katex';
|
import rehypeKatex from 'rehype-katex';
|
||||||
import rehypeStringify from 'rehype-stringify';
|
import rehypeStringify from 'rehype-stringify';
|
||||||
import { copyCodeToClipboard, preprocessLaTeX } from '$lib/utils';
|
import type { Root as HastRoot, RootContent as HastRootContent } from 'hast';
|
||||||
import { rehypeRestoreTableHtml } from '$lib/markdown/table-html-restorer';
|
import type { Root as MdastRoot } from 'mdast';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
|
import { onDestroy } from 'svelte';
|
||||||
|
import { rehypeRestoreTableHtml } from '$lib/markdown/table-html-restorer';
|
||||||
|
import { remarkLiteralHtml } from '$lib/markdown/literal-html';
|
||||||
|
import { copyCodeToClipboard, preprocessLaTeX } from '$lib/utils';
|
||||||
import '$styles/katex-custom.scss';
|
import '$styles/katex-custom.scss';
|
||||||
|
|
||||||
import githubDarkCss from 'highlight.js/styles/github-dark.css?inline';
|
import githubDarkCss from 'highlight.js/styles/github-dark.css?inline';
|
||||||
import githubLightCss from 'highlight.js/styles/github.css?inline';
|
import githubLightCss from 'highlight.js/styles/github.css?inline';
|
||||||
import { mode } from 'mode-watcher';
|
import { mode } from 'mode-watcher';
|
||||||
import { remarkLiteralHtml } from '$lib/markdown/literal-html';
|
import { v4 as uuid } from 'uuid';
|
||||||
import CodePreviewDialog from './CodePreviewDialog.svelte';
|
import CodePreviewDialog from './CodePreviewDialog.svelte';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
@ -23,33 +26,24 @@
|
||||||
class?: string;
|
class?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface MarkdownBlock {
|
||||||
|
id: string;
|
||||||
|
html: string;
|
||||||
|
}
|
||||||
|
|
||||||
let { content, class: className = '' }: Props = $props();
|
let { content, class: className = '' }: Props = $props();
|
||||||
|
|
||||||
let containerRef = $state<HTMLDivElement>();
|
let containerRef = $state<HTMLDivElement>();
|
||||||
let processedHtml = $state('');
|
let renderedBlocks = $state<MarkdownBlock[]>([]);
|
||||||
|
let unstableBlockHtml = $state('');
|
||||||
let previewDialogOpen = $state(false);
|
let previewDialogOpen = $state(false);
|
||||||
let previewCode = $state('');
|
let previewCode = $state('');
|
||||||
let previewLanguage = $state('text');
|
let previewLanguage = $state('text');
|
||||||
|
|
||||||
function loadHighlightTheme(isDark: boolean) {
|
let pendingMarkdown: string | null = null;
|
||||||
if (!browser) return;
|
let isProcessing = false;
|
||||||
|
|
||||||
const existingThemes = document.querySelectorAll('style[data-highlight-theme]');
|
const themeStyleId = `highlight-theme-${uuid()}`;
|
||||||
existingThemes.forEach((style) => style.remove());
|
|
||||||
|
|
||||||
const style = document.createElement('style');
|
|
||||||
style.setAttribute('data-highlight-theme', 'true');
|
|
||||||
style.textContent = isDark ? githubDarkCss : githubLightCss;
|
|
||||||
|
|
||||||
document.head.appendChild(style);
|
|
||||||
}
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
const currentMode = mode.current;
|
|
||||||
const isDark = currentMode === 'dark';
|
|
||||||
|
|
||||||
loadHighlightTheme(isDark);
|
|
||||||
});
|
|
||||||
|
|
||||||
let processor = $derived(() => {
|
let processor = $derived(() => {
|
||||||
return remark()
|
return remark()
|
||||||
|
|
@ -64,41 +58,44 @@
|
||||||
.use(rehypeStringify); // Convert to HTML string
|
.use(rehypeStringify); // Convert to HTML string
|
||||||
});
|
});
|
||||||
|
|
||||||
function enhanceLinks(html: string): string {
|
/**
|
||||||
if (!html.includes('<a')) {
|
* Removes click event listeners from copy and preview buttons.
|
||||||
return html;
|
* Called on component destroy.
|
||||||
|
*/
|
||||||
|
function cleanupEventListeners() {
|
||||||
|
if (!containerRef) return;
|
||||||
|
|
||||||
|
const copyButtons = containerRef.querySelectorAll<HTMLButtonElement>('.copy-code-btn');
|
||||||
|
const previewButtons = containerRef.querySelectorAll<HTMLButtonElement>('.preview-code-btn');
|
||||||
|
|
||||||
|
for (const button of copyButtons) {
|
||||||
|
button.removeEventListener('click', handleCopyClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
const tempDiv = document.createElement('div');
|
for (const button of previewButtons) {
|
||||||
tempDiv.innerHTML = html;
|
button.removeEventListener('click', handlePreviewClick);
|
||||||
|
}
|
||||||
// Make all links open in new tabs
|
|
||||||
const linkElements = tempDiv.querySelectorAll('a[href]');
|
|
||||||
let mutated = false;
|
|
||||||
|
|
||||||
for (const link of linkElements) {
|
|
||||||
const target = link.getAttribute('target');
|
|
||||||
const rel = link.getAttribute('rel');
|
|
||||||
|
|
||||||
if (target !== '_blank' || rel !== 'noopener noreferrer') {
|
|
||||||
mutated = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
link.setAttribute('target', '_blank');
|
/**
|
||||||
link.setAttribute('rel', 'noopener noreferrer');
|
* Removes this component's highlight.js theme style from the document head.
|
||||||
}
|
* Called on component destroy to clean up injected styles.
|
||||||
|
*/
|
||||||
return mutated ? tempDiv.innerHTML : html;
|
function cleanupHighlightTheme() {
|
||||||
|
if (!browser) return;
|
||||||
|
|
||||||
|
const existingTheme = document.getElementById(themeStyleId);
|
||||||
|
existingTheme?.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enhances code blocks with wrapper, header, language label, and action buttons.
|
||||||
|
* Adds copy button to all code blocks and preview button to HTML blocks.
|
||||||
|
* @param html - The HTML string containing code blocks to enhance
|
||||||
|
* @returns Enhanced HTML string with wrapped code blocks
|
||||||
|
*/
|
||||||
function enhanceCodeBlocks(html: string): string {
|
function enhanceCodeBlocks(html: string): string {
|
||||||
if (!html.includes('<pre')) {
|
return processHtml(html, '<pre', (tempDiv) => {
|
||||||
return html;
|
|
||||||
}
|
|
||||||
|
|
||||||
const tempDiv = document.createElement('div');
|
|
||||||
tempDiv.innerHTML = html;
|
|
||||||
|
|
||||||
const preElements = tempDiv.querySelectorAll('pre');
|
const preElements = tempDiv.querySelectorAll('pre');
|
||||||
let mutated = false;
|
let mutated = false;
|
||||||
|
|
||||||
|
|
@ -122,7 +119,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawCode = codeElement.textContent || '';
|
const rawCode = codeElement.textContent || '';
|
||||||
const codeId = `code-${Date.now()}-${index}`;
|
const codeId = `code-${uuid()}-${index}`;
|
||||||
codeElement.setAttribute('data-code-id', codeId);
|
codeElement.setAttribute('data-code-id', codeId);
|
||||||
codeElement.setAttribute('data-raw-code', rawCode);
|
codeElement.setAttribute('data-raw-code', rawCode);
|
||||||
|
|
||||||
|
|
@ -143,8 +140,8 @@
|
||||||
copyButton.setAttribute('type', 'button');
|
copyButton.setAttribute('type', 'button');
|
||||||
|
|
||||||
copyButton.innerHTML = `
|
copyButton.innerHTML = `
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy-icon lucide-copy"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy-icon lucide-copy"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const actions = document.createElement('div');
|
const actions = document.createElement('div');
|
||||||
actions.className = 'code-block-actions';
|
actions.className = 'code-block-actions';
|
||||||
|
|
@ -159,8 +156,8 @@
|
||||||
previewButton.setAttribute('type', 'button');
|
previewButton.setAttribute('type', 'button');
|
||||||
|
|
||||||
previewButton.innerHTML = `
|
previewButton.innerHTML = `
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-eye lucide-eye-icon"><path d="M2.062 12.345a1 1 0 0 1 0-.69C3.5 7.73 7.36 5 12 5s8.5 2.73 9.938 6.655a1 1 0 0 1 0 .69C20.5 16.27 16.64 19 12 19s-8.5-2.73-9.938-6.655"/><circle cx="12" cy="12" r="3"/></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-eye lucide-eye-icon"><path d="M2.062 12.345a1 1 0 0 1 0-.69C3.5 7.73 7.36 5 12 5s8.5 2.73 9.938 6.655a1 1 0 0 1 0 .69C20.5 16.27 16.64 19 12 19s-8.5-2.73-9.938-6.655"/><circle cx="12" cy="12" r="3"/></svg>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
actions.appendChild(previewButton);
|
actions.appendChild(previewButton);
|
||||||
}
|
}
|
||||||
|
|
@ -175,25 +172,60 @@
|
||||||
pre.parentNode?.replaceChild(wrapper, pre);
|
pre.parentNode?.replaceChild(wrapper, pre);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mutated ? tempDiv.innerHTML : html;
|
return mutated;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processMarkdown(text: string): Promise<string> {
|
/**
|
||||||
try {
|
* Enhances links to open in new tabs with security attributes.
|
||||||
let normalized = preprocessLaTeX(text);
|
* Sets target="_blank" and rel="noopener noreferrer" on all anchor elements.
|
||||||
const result = await processor().process(normalized);
|
* @param html - The HTML string containing links to enhance
|
||||||
const html = String(result);
|
* @returns Enhanced HTML string with modified link attributes
|
||||||
const enhancedLinks = enhanceLinks(html);
|
*/
|
||||||
|
function enhanceLinks(html: string): string {
|
||||||
|
return processHtml(html, '<a', (tempDiv) => {
|
||||||
|
const linkElements = tempDiv.querySelectorAll('a[href]');
|
||||||
|
let mutated = false;
|
||||||
|
|
||||||
return enhanceCodeBlocks(enhancedLinks);
|
for (const link of linkElements) {
|
||||||
} catch (error) {
|
const target = link.getAttribute('target');
|
||||||
console.error('Markdown processing error:', error);
|
const rel = link.getAttribute('rel');
|
||||||
|
|
||||||
// Fallback to plain text with line breaks
|
// Only mutate if attributes need to change
|
||||||
return text.replace(/\n/g, '<br>');
|
if (target !== '_blank' || rel !== 'noopener noreferrer') {
|
||||||
|
link.setAttribute('target', '_blank');
|
||||||
|
link.setAttribute('rel', 'noopener noreferrer');
|
||||||
|
mutated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return mutated;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the appropriate highlight.js theme based on dark/light mode.
|
||||||
|
* Injects a scoped style element into the document head.
|
||||||
|
* @param isDark - Whether to load the dark theme (true) or light theme (false)
|
||||||
|
*/
|
||||||
|
function loadHighlightTheme(isDark: boolean) {
|
||||||
|
if (!browser) return;
|
||||||
|
|
||||||
|
const existingTheme = document.getElementById(themeStyleId);
|
||||||
|
existingTheme?.remove();
|
||||||
|
|
||||||
|
const style = document.createElement('style');
|
||||||
|
style.id = themeStyleId;
|
||||||
|
style.textContent = isDark ? githubDarkCss : githubLightCss;
|
||||||
|
|
||||||
|
document.head.appendChild(style);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts code information from a button click target within a code block.
|
||||||
|
* @param target - The clicked button element
|
||||||
|
* @returns Object with rawCode and language, or null if extraction fails
|
||||||
|
*/
|
||||||
function getCodeInfoFromTarget(target: HTMLElement) {
|
function getCodeInfoFromTarget(target: HTMLElement) {
|
||||||
const wrapper = target.closest('.code-block-wrapper');
|
const wrapper = target.closest('.code-block-wrapper');
|
||||||
|
|
||||||
|
|
@ -222,6 +254,28 @@
|
||||||
return { rawCode, language };
|
return { rawCode, language };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a unique identifier for a HAST node based on its position.
|
||||||
|
* Used for stable block identification during incremental rendering.
|
||||||
|
* @param node - The HAST root content node
|
||||||
|
* @param indexFallback - Fallback index if position is unavailable
|
||||||
|
* @returns Unique string identifier for the node
|
||||||
|
*/
|
||||||
|
function getHastNodeId(node: HastRootContent, indexFallback: number): string {
|
||||||
|
const position = node.position;
|
||||||
|
|
||||||
|
if (position?.start?.offset != null && position?.end?.offset != null) {
|
||||||
|
return `hast-${position.start.offset}-${position.end.offset}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${node.type}-${indexFallback}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles click events on copy buttons within code blocks.
|
||||||
|
* Copies the raw code content to the clipboard.
|
||||||
|
* @param event - The click event from the copy button
|
||||||
|
*/
|
||||||
async function handleCopyClick(event: Event) {
|
async function handleCopyClick(event: Event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
@ -245,6 +299,25 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles preview dialog open state changes.
|
||||||
|
* Clears preview content when dialog is closed.
|
||||||
|
* @param open - Whether the dialog is being opened or closed
|
||||||
|
*/
|
||||||
|
function handlePreviewDialogOpenChange(open: boolean) {
|
||||||
|
previewDialogOpen = open;
|
||||||
|
|
||||||
|
if (!open) {
|
||||||
|
previewCode = '';
|
||||||
|
previewLanguage = 'text';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles click events on preview buttons within HTML code blocks.
|
||||||
|
* Opens a preview dialog with the rendered HTML content.
|
||||||
|
* @param event - The click event from the preview button
|
||||||
|
*/
|
||||||
function handlePreviewClick(event: Event) {
|
function handlePreviewClick(event: Event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
@ -266,6 +339,81 @@
|
||||||
previewDialogOpen = true;
|
previewDialogOpen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to process HTML with a temporary DOM element.
|
||||||
|
* Returns original HTML if not in browser or tag not found.
|
||||||
|
*/
|
||||||
|
function processHtml(
|
||||||
|
html: string,
|
||||||
|
tagCheck: string,
|
||||||
|
processor: (tempDiv: HTMLDivElement) => boolean
|
||||||
|
): string {
|
||||||
|
if (!browser || !html.includes(tagCheck)) {
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tempDiv = document.createElement('div');
|
||||||
|
tempDiv.innerHTML = html;
|
||||||
|
|
||||||
|
const mutated = processor(tempDiv);
|
||||||
|
|
||||||
|
return mutated ? tempDiv.innerHTML : html;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes markdown content into stable and unstable HTML blocks.
|
||||||
|
* Uses incremental rendering: stable blocks are cached, unstable block is re-rendered.
|
||||||
|
* @param markdown - The raw markdown string to process
|
||||||
|
*/
|
||||||
|
async function processMarkdown(markdown: string) {
|
||||||
|
if (!markdown) {
|
||||||
|
renderedBlocks = [];
|
||||||
|
unstableBlockHtml = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalized = preprocessLaTeX(markdown);
|
||||||
|
const processorInstance = processor();
|
||||||
|
const ast = processorInstance.parse(normalized) as MdastRoot;
|
||||||
|
const processedRoot = (await processorInstance.run(ast)) as HastRoot;
|
||||||
|
const processedChildren = processedRoot.children ?? [];
|
||||||
|
const stableCount = Math.max(processedChildren.length - 1, 0);
|
||||||
|
const nextBlocks: MarkdownBlock[] = [];
|
||||||
|
|
||||||
|
for (let index = 0; index < stableCount; index++) {
|
||||||
|
const hastChild = processedChildren[index];
|
||||||
|
const id = getHastNodeId(hastChild, index);
|
||||||
|
const existing = renderedBlocks[index];
|
||||||
|
|
||||||
|
if (existing && existing.id === id) {
|
||||||
|
nextBlocks.push(existing);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const html = stringifyProcessedNode(
|
||||||
|
processorInstance,
|
||||||
|
processedRoot,
|
||||||
|
processedChildren[index]
|
||||||
|
);
|
||||||
|
|
||||||
|
nextBlocks.push({ id, html });
|
||||||
|
}
|
||||||
|
|
||||||
|
let unstableHtml = '';
|
||||||
|
|
||||||
|
if (processedChildren.length > stableCount) {
|
||||||
|
const unstableChild = processedChildren[stableCount];
|
||||||
|
unstableHtml = stringifyProcessedNode(processorInstance, processedRoot, unstableChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderedBlocks = nextBlocks;
|
||||||
|
unstableBlockHtml = unstableHtml;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attaches click event listeners to copy and preview buttons in code blocks.
|
||||||
|
* Uses data-listener-bound attribute to prevent duplicate bindings.
|
||||||
|
*/
|
||||||
function setupCodeBlockActions() {
|
function setupCodeBlockActions() {
|
||||||
if (!containerRef) return;
|
if (!containerRef) return;
|
||||||
|
|
||||||
|
|
@ -287,40 +435,99 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlePreviewDialogOpenChange(open: boolean) {
|
/**
|
||||||
previewDialogOpen = open;
|
* Converts a single HAST node to an enhanced HTML string.
|
||||||
|
* Applies link and code block enhancements to the output.
|
||||||
|
* @param processorInstance - The remark/rehype processor instance
|
||||||
|
* @param processedRoot - The full processed HAST root (for context)
|
||||||
|
* @param child - The specific HAST child node to stringify
|
||||||
|
* @returns Enhanced HTML string representation of the node
|
||||||
|
*/
|
||||||
|
function stringifyProcessedNode(
|
||||||
|
processorInstance: ReturnType<typeof processor>,
|
||||||
|
processedRoot: HastRoot,
|
||||||
|
child: unknown
|
||||||
|
) {
|
||||||
|
const root: HastRoot = {
|
||||||
|
...(processedRoot as HastRoot),
|
||||||
|
children: [child as never]
|
||||||
|
};
|
||||||
|
|
||||||
if (!open) {
|
const html = processorInstance.stringify(root);
|
||||||
previewCode = '';
|
|
||||||
previewLanguage = 'text';
|
return enhanceCodeBlocks(enhanceLinks(html));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$effect(() => {
|
/**
|
||||||
if (content) {
|
* Queues markdown for processing with coalescing support.
|
||||||
processMarkdown(content)
|
* Only processes the latest markdown when multiple updates arrive quickly.
|
||||||
.then((result) => {
|
* @param markdown - The markdown content to render
|
||||||
processedHtml = result;
|
*/
|
||||||
})
|
async function updateRenderedBlocks(markdown: string) {
|
||||||
.catch((error) => {
|
pendingMarkdown = markdown;
|
||||||
|
|
||||||
|
if (isProcessing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isProcessing = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (pendingMarkdown !== null) {
|
||||||
|
const nextMarkdown = pendingMarkdown;
|
||||||
|
pendingMarkdown = null;
|
||||||
|
|
||||||
|
await processMarkdown(nextMarkdown);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
console.error('Failed to process markdown:', error);
|
console.error('Failed to process markdown:', error);
|
||||||
processedHtml = content.replace(/\n/g, '<br>');
|
renderedBlocks = [];
|
||||||
});
|
unstableBlockHtml = markdown.replace(/\n/g, '<br>');
|
||||||
} else {
|
} finally {
|
||||||
processedHtml = '';
|
isProcessing = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
const currentMode = mode.current;
|
||||||
|
const isDark = currentMode === 'dark';
|
||||||
|
|
||||||
|
loadHighlightTheme(isDark);
|
||||||
});
|
});
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (containerRef && processedHtml) {
|
updateRenderedBlocks(content);
|
||||||
|
});
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
const hasRenderedBlocks = renderedBlocks.length > 0;
|
||||||
|
const hasUnstableBlock = Boolean(unstableBlockHtml);
|
||||||
|
|
||||||
|
if ((hasRenderedBlocks || hasUnstableBlock) && containerRef) {
|
||||||
setupCodeBlockActions();
|
setupCodeBlockActions();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
cleanupEventListeners();
|
||||||
|
cleanupHighlightTheme();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div bind:this={containerRef} class={className}>
|
<div bind:this={containerRef} class={className}>
|
||||||
|
{#each renderedBlocks as block (block.id)}
|
||||||
|
<div class="markdown-block" data-block-id={block.id}>
|
||||||
<!-- eslint-disable-next-line no-at-html-tags -->
|
<!-- eslint-disable-next-line no-at-html-tags -->
|
||||||
{@html processedHtml}
|
{@html block.html}
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
|
||||||
|
{#if unstableBlockHtml}
|
||||||
|
<div class="markdown-block markdown-block--unstable" data-block-id="unstable">
|
||||||
|
<!-- eslint-disable-next-line no-at-html-tags -->
|
||||||
|
{@html unstableBlockHtml}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<CodePreviewDialog
|
<CodePreviewDialog
|
||||||
|
|
@ -331,6 +538,11 @@
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
.markdown-block,
|
||||||
|
.markdown-block--unstable {
|
||||||
|
display: contents;
|
||||||
|
}
|
||||||
|
|
||||||
/* Base typography styles */
|
/* Base typography styles */
|
||||||
div :global(p:not(:last-child)) {
|
div :global(p:not(:last-child)) {
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue