Skip to content

Commit de59065

Browse files
committed
chore: update .gitignore to include Nx workspace caches and remove specific cache path
fix: enhance marked.utils.ts to support new table and image rendering logic chore: update package-lock.json with new dependencies and versions chore: update package.json to include @tailwindcss/postcss and adjust esbuild dependency fix: correct postcss.config.js to use array format for plugins
1 parent dfce2eb commit de59065

File tree

6 files changed

+690
-17
lines changed

6 files changed

+690
-17
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,6 @@ dmypy.json
158158
cython_debug/
159159

160160
**/.DS_Store
161+
162+
# Nx workspace caches (frontend uses a nested Nx workspace)
163+
**/.nx/

services/frontend/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ testem.log
3737
.DS_Store
3838
Thumbs.db
3939

40-
.nx/cache
40+
.nx/

services/frontend/libs/shared/utils/src/lib/marked.utils.ts

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ import { newUid } from "./uuid.util";
44
export const initializeMarkdown = () => {
55
const renderer = new marked.Renderer();
66

7-
renderer.table = (header, body) => {
8-
return `<table class="table table-xs">${header}${body}</table>`;
7+
// Preserve default behavior while injecting our own CSS classes.
8+
const anyRenderer = renderer as unknown as Record<string, any>;
9+
const originalTable = anyRenderer['table']?.bind(renderer) as ((...args: any[]) => string) | undefined;
10+
anyRenderer['table'] = (...args: any[]): string => {
11+
// Marked >= v16 provides a token argument; older versions pass (header, body)
12+
if (args.length === 1 && typeof args[0] === 'object') {
13+
const html = originalTable ? originalTable(args[0]) : '';
14+
return html
15+
? html.replace('<table>', '<table class="table table-xs">')
16+
: '<table class="table table-xs"></table>';
17+
}
18+
const [header, body] = args as [string, string];
19+
return `<table class="table table-xs">${header ?? ''}${body ?? ''}</table>`;
920
};
1021

1122
const toggleModal = (modalId: string) => {
@@ -15,25 +26,43 @@ export const initializeMarkdown = () => {
1526
}
1627
};
1728

18-
document.addEventListener('click', (event: any) => {
19-
if (event?.target?.matches('.image-modal-trigger')) {
20-
const modalId = event.target.getAttribute('data-modal-id');
21-
toggleModal(modalId);
29+
document.addEventListener('click', (event: MouseEvent) => {
30+
const target = event.target as HTMLElement | null;
31+
if (target && target.matches('.image-modal-trigger')) {
32+
const modalId = target.getAttribute('data-modal-id');
33+
if (modalId) toggleModal(modalId);
2234
}
2335
});
2436

25-
renderer.image = (href, title, text) => {
37+
const originalImage = anyRenderer['image']?.bind(renderer) as ((...args: any[]) => string) | undefined;
38+
anyRenderer['image'] = (...args: any[]): string => {
39+
let href = '' as string | undefined;
40+
let title = null as string | null;
41+
let text = '' as string | undefined;
42+
// token form
43+
if (args.length === 1 && typeof args[0] === 'object') {
44+
const token = args[0] as { href?: string; title?: string | null; text?: string };
45+
href = token.href;
46+
title = token.title ?? null;
47+
text = token.text;
48+
} else {
49+
// legacy form (href, title, text)
50+
[href, title, text] = args as [string, string | null, string];
51+
}
2652
const imageId = newUid();
53+
const titleAttr = title ? ` title="${title}"` : '';
54+
const src = href ?? '';
55+
const alt = text ?? '';
2756
return `
2857
<div class="py-2 mb-1">
29-
<img src="${href}" alt="${text}" title="${title}" class="cursor-pointer w-full image-modal-trigger" data-modal-id="${imageId}"/>
58+
<img src="${src}" alt="${alt}"${titleAttr} class="cursor-pointer w-full image-modal-trigger" data-modal-id="${imageId}"/>
3059
</div>
31-
<dialog id="${imageId}" className="modal" style="width:80%;">
32-
<div className="modal-box w-full">
60+
<dialog id="${imageId}" class="modal" style="width:80%;">
61+
<div class="modal-box w-full">
3362
<form method="dialog">
3463
<button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2">✕</button>
3564
</form>
36-
<img src="${href}" alt="${text}" class="w-full min-w-96"/>
65+
<img src="${src}" alt="${alt}" class="w-full min-w-96"/>
3766
</div>
3867
</dialog>
3968
`;

0 commit comments

Comments
 (0)