Files
homebox/frontend/components/global/Markdown.vue
Michael Manganiello 62f6121260 feat: Add plugin to set image sizes in Markdown (#901)
* feat: Add plugin to set image sizes in Markdown

Install the `@mdit/plugin-img-size` plugin [1] to allow setting image sizes
in Markdown content. This improves the image rendering capabilities for
Markdown blocks.

Before (no resizing possible):

```markdown
![logo](https://raw.githubusercontent.com/sysadminsmedia/homebox/refs/tags/v0.20.2/docs/public/lilbox.svg)
```

After (size specified):

```markdown
![logo =100x](https://raw.githubusercontent.com/sysadminsmedia/homebox/refs/tags/v0.20.2/docs/public/lilbox.svg)
```

[1] https://mdit-plugins.github.io/img-size.html

* Update @types/markdown-it to match markdown-it version
2025-07-16 05:58:24 +00:00

42 lines
1.1 KiB
Vue

<script setup lang="ts">
import MarkdownIt from "markdown-it";
import { imgSize } from "@mdit/plugin-img-size";
import DOMPurify from "dompurify";
type Props = {
source: string | null | undefined;
};
const props = withDefaults(defineProps<Props>(), {
source: null,
});
const md = new MarkdownIt({
html: true,
linkify: true,
typographer: true,
}).use(imgSize);
const raw = computed(() => {
const html = md.render(props.source || "").replace(/\n$/, ""); // remove trailing newline
return DOMPurify.sanitize(html);
});
</script>
<template>
<!-- eslint-disable-next-line vue/no-v-html -->
<div class="markdown text-wrap break-words" v-html="raw"></div>
</template>
<style scoped>
* {
word-wrap: break-word; /*Fix for long words going out of emelent bounds and issue #407 */
overflow-wrap: break-word; /*Fix for long words going out of emelent bounds and issue #407 */
white-space: pre-wrap; /*Fix for long words going out of emelent bounds and issue #407 */
}
.markdown {
max-width: 100%;
overflow: hidden; /*Fix for long words going out of emelent bounds and issue #407 */
}
</style>