|
| 1 | +<template> |
| 2 | + <!-- The content is our own markdown files, not user input --> |
| 3 | + <div class="markdown-content" v-html="renderedHelp"></div> |
| 4 | +</template> |
| 5 | + |
| 6 | +<script setup lang="ts"> |
| 7 | +import {computed, ComputedRef} from "vue"; |
| 8 | +import {useI18n} from "vue-i18n"; |
| 9 | +import {Marked, Token, Tokens} from "marked"; |
| 10 | +import DataVisuHelpEN from "@/components/visualization/doc/DataVisuHelpEN.md?raw"; |
| 11 | +import DataVisuHelpFR from "@/components/visualization/doc/DataVisuHelpFR.md?raw"; |
| 12 | +
|
| 13 | +/** |
| 14 | + * Help of the DataVisuGraphic: its interactions (click, right-click, zoom, menu), in the current language. |
| 15 | + * |
| 16 | + * The markdown files reference their screenshots as ``, next to them in the doc folder. |
| 17 | + */ |
| 18 | +
|
| 19 | +//#region Private |
| 20 | +//#region Plugins & services |
| 21 | +const {locale} = useI18n(); |
| 22 | +
|
| 23 | +/** |
| 24 | + * URL of each screenshot of the doc folder, by its path in the markdown. The markdown is read as raw text, so Vite |
| 25 | + * doesn't resolve its image paths by itself. |
| 26 | + */ |
| 27 | +const screenshotUrls: Map<string, string> = new Map( |
| 28 | + Object.entries(import.meta.glob<string>("./doc/*.png", {eager: true, query: "?url", import: "default"})) |
| 29 | + .map(([path, url]: [string, string]) => [path.replace("./doc/", "./"), url]) |
| 30 | +); |
| 31 | +
|
| 32 | +/** |
| 33 | + * Own instance of marked, so that the image paths are only replaced in this help, not in the other markdown pages |
| 34 | + */ |
| 35 | +const helpMarked: Marked = new Marked({walkTokens: resolveScreenshot}); |
| 36 | +//#endregion |
| 37 | +
|
| 38 | +//#region Data & Computed |
| 39 | +const renderedHelp: ComputedRef<string> = computed<string>(() => |
| 40 | + helpMarked.parse(locale.value === "fr" ? DataVisuHelpFR : DataVisuHelpEN, {async: false}) as string |
| 41 | +); |
| 42 | +//#endregion |
| 43 | +
|
| 44 | +//#region Methods |
| 45 | +/** |
| 46 | + * Called by marked on each piece of the parsed markdown, before it is rendered as HTML: gives the images the real URL |
| 47 | + * of their screenshot |
| 48 | + */ |
| 49 | +function resolveScreenshot(token: Token): void { |
| 50 | + if (token.type === "image") { |
| 51 | + const image: Tokens.Image = token as Tokens.Image; |
| 52 | + image.href = screenshotUrls.get(image.href) ?? image.href; |
| 53 | + } |
| 54 | +} |
| 55 | +//#endregion |
| 56 | +//#endregion |
| 57 | +</script> |
| 58 | + |
| 59 | +<style scoped lang="scss"> |
| 60 | +/* Screenshots of any size: never wider than the modal, proportions kept, framed to stand out from the white modal */ |
| 61 | +.markdown-content :deep(img) { |
| 62 | + display: block; |
| 63 | + max-width: 100%; |
| 64 | + height: auto; |
| 65 | + margin: 8px auto 24px; |
| 66 | + border: 1px solid #e0e0e6; |
| 67 | + border-radius: 4px; |
| 68 | +} |
| 69 | +</style> |
0 commit comments