Skip to content

Commit

Permalink
feat(nx-dev): show alt text as label below markdown images
Browse files Browse the repository at this point in the history
  • Loading branch information
juristr committed Jan 31, 2025
1 parent 999dcfb commit a4f07db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nx-dev/nx-dev/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ iframe[src*='youtube'] {
aspect-ratio: 16 / 9;
}
.prose iframe,
.prose img {
.prose img:not(figure img) {
display: block;
margin: 2rem auto;
}
Expand Down
16 changes: 10 additions & 6 deletions nx-dev/ui-markdoc/src/lib/nodes/image.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { transformImagePath } from './helpers/transform-image-path';

export const getImageSchema = (documentFilePath: string): Schema => ({
render: 'img',
render: 'figure',
attributes: {
src: { type: 'String', required: true },
alt: { type: 'String', required: true },
Expand All @@ -17,11 +17,15 @@ export const getImageSchema = (documentFilePath: string): Schema => ({
const attributes = node.transformAttributes(config);
const children = node.transformChildren(config);
const src = transformImagePath(documentFilePath)(attributes['src']);
const alt = attributes['alt'];

return new Tag(
this.render,
{ ...attributes, src, loading: 'lazy' },
children
);
return new Tag(this.render, { className: 'not-prose my-8 text-center' }, [
new Tag('img', { src, alt, loading: 'lazy', className: 'mx-auto !my-0' }),
new Tag(
'figcaption',
{ className: 'mt-2 text-sm text-slate-600 dark:text-slate-400' },
[alt]
),
]);
},
});

0 comments on commit a4f07db

Please sign in to comment.