feat: version 2.9.1 -- resaltado de sintaxis en bloques de codigo de documentos .md
Los bloques de codigo dentro de un .md visto en Documentos ahora tienen colores de token (highlight.js + marked-highlight), con el tema "Visual Studio" claro/oscuro para que se vea parecido a VSCode y se adapte solo al tema de la app. Se usa highlight.js/lib/core y solo se registran los lenguajes esperados en este proyecto (js/ts, bash, json, python, sql, yaml, html/xml, css, ini, dockerfile, markdown) para no inflar el bundle con el paquete completo. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,11 +6,15 @@ import { listAttachments, uploadAttachment, deleteAttachment, downloadAttachment
|
||||
import { renderMarkdown } from '../utils/renderMarkdown.js';
|
||||
import { Button } from './Button.jsx';
|
||||
import { DetailPopup } from './DetailPopup.jsx';
|
||||
// Tema de colores de bloques de codigo al estilo Visual Studio/VSCode (claro y oscuro),
|
||||
// inyectado solo mientras se ve un .md -- ?inline evita que Vite lo aplique global siempre.
|
||||
import hljsLight from 'highlight.js/styles/vs.css?inline';
|
||||
import hljsDark from 'highlight.js/styles/vs2015.css?inline';
|
||||
|
||||
const VIEWABLE_MIME = new Set(['text/plain', 'text/markdown']);
|
||||
|
||||
export function AttachmentsPanel({ entityType, entityId }) {
|
||||
const { t, openDialog } = useUi();
|
||||
const { t, openDialog, theme } = useUi();
|
||||
const runAction = useAction();
|
||||
const { data: files, reload } = useAsync(() => listAttachments(entityType, entityId), [entityType, entityId]);
|
||||
const inputRef = useRef(null);
|
||||
@@ -83,8 +87,11 @@ export function AttachmentsPanel({ entityType, entityId }) {
|
||||
{viewLoading ? (
|
||||
<div className="text-muted">{t('common_loading')}</div>
|
||||
) : viewing?.mime_type === 'text/markdown' ? (
|
||||
// eslint-disable-next-line react/no-danger -- sanitizado con DOMPurify en renderMarkdown()
|
||||
<div className="markdown-view" dangerouslySetInnerHTML={{ __html: renderMarkdown(viewContent) }} />
|
||||
<>
|
||||
<style>{theme === 'light' ? hljsLight : hljsDark}</style>
|
||||
{/* eslint-disable-next-line react/no-danger -- sanitizado con DOMPurify en renderMarkdown() */}
|
||||
<div className="markdown-view" dangerouslySetInnerHTML={{ __html: renderMarkdown(viewContent) }} />
|
||||
</>
|
||||
) : (
|
||||
<pre className="text-view">{viewContent}</pre>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user