diff --git a/plugin/src/MarkdownRenderer.module.css b/plugin/src/MarkdownRenderer.module.css new file mode 100644 index 00000000..49aade26 --- /dev/null +++ b/plugin/src/MarkdownRenderer.module.css @@ -0,0 +1,12 @@ +.sourceLink { + display: inline-block; + font-size: 0.7em; + vertical-align: super; + padding: 0 0.15em; + text-decoration: none; +} + +.sourceLink:focus-visible { + outline: 2px solid currentColor; + outline-offset: 2px; +} diff --git a/plugin/src/components/DownloadDropdown.tsx b/plugin/src/components/DownloadDropdown.tsx index 2ec5e545..f7456c18 100644 --- a/plugin/src/components/DownloadDropdown.tsx +++ b/plugin/src/components/DownloadDropdown.tsx @@ -6,6 +6,7 @@ import { toast } from 'sonner' import { exportPipelineResultAsDocx } from '@/client' import styles from '@/components/DownloadDropdown.module.css' import { triggerBlobDownload } from '@/download' +import { stripStatementSources } from '@/statement-sources' type DownloadDropdownProps = { markdown: string @@ -14,7 +15,7 @@ type DownloadDropdownProps = { } /** - * Download menu for a pipeline result, offering the raw markdown or a Word export. + * Download menu for a pipeline result, offering Markdown or Word without source metadata. * * The markdown passed in is the editor's current text, so unsaved edits are downloaded too. */ @@ -58,7 +59,9 @@ export function DownloadDropdown({ markdown, runId, baseName }: DownloadDropdown return } - const blob = new Blob([markdown], { type: 'text/markdown;charset=utf-8' }) + const blob = new Blob([stripStatementSources(markdown)], { + type: 'text/markdown;charset=utf-8', + }) triggerBlobDownload(blob, `${fileBaseName}.md`) toast.success('Markdown download has started.') } diff --git a/plugin/src/components/PipelineResultPanel.tsx b/plugin/src/components/PipelineResultPanel.tsx index 8c773950..8b760824 100644 --- a/plugin/src/components/PipelineResultPanel.tsx +++ b/plugin/src/components/PipelineResultPanel.tsx @@ -10,9 +10,11 @@ import { saveEditedPipelineResult } from '@/client' import { DownloadDropdown } from '@/components/DownloadDropdown' import styles from '@/components/PipelineResultPanel.module.css' import { MarkdownRenderer } from '@/markdown-utils' +import { stripStatementSources } from '@/statement-sources' import type { PipelineStatusResponse, ResultRenderMode } from '@/types' type PipelineResultPanelProps = { + projectUuid: string resultMarkdown: string | null resultRunId: string | null downloadBaseName: string @@ -20,6 +22,7 @@ type PipelineResultPanelProps = { } export function PipelineResultPanel({ + projectUuid, resultMarkdown, resultRunId, downloadBaseName, @@ -45,7 +48,7 @@ export function PipelineResultPanel({ } try { - await navigator.clipboard.writeText(displayedResultMarkdown) + await navigator.clipboard.writeText(stripStatementSources(displayedResultMarkdown)) toast.success('Markdown has been copied to the clipboard.') } catch { toast.error('Failed to copy markdown to the clipboard.') @@ -156,7 +159,10 @@ export function PipelineResultPanel({ /> ) : ( - + )} diff --git a/plugin/src/components/ProjectTab.tsx b/plugin/src/components/ProjectTab.tsx index e132b796..211fcb47 100644 --- a/plugin/src/components/ProjectTab.tsx +++ b/plugin/src/components/ProjectTab.tsx @@ -171,7 +171,11 @@ export default function ProjectTab({
{selectedRunId ? ( - + ) : ( void + projectUuid: string }) { if (run.status === 'queued' || run.status === 'running') { return ( @@ -127,6 +130,7 @@ function RunDetailPanelBody({ return ( {getRunTimeLabel(run)} - + ) } diff --git a/plugin/src/markdown-utils.tsx b/plugin/src/markdown-utils.tsx index e153924f..9bac47a6 100644 --- a/plugin/src/markdown-utils.tsx +++ b/plugin/src/markdown-utils.tsx @@ -2,21 +2,44 @@ import { Prose } from '@ds-wizard/plugin-sdk/ui/Prose' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' +import styles from '@/MarkdownRenderer.module.css' +import { prepareStatementSources } from '@/statement-sources' + type MarkdownRendererProps = { markdown: string + projectUuid: string } -/** Generated Markdown, typeset by the wizard's `Prose`; raw HTML in it is skipped. */ -export function MarkdownRenderer({ markdown }: MarkdownRendererProps) { +export function MarkdownRenderer({ markdown, projectUuid }: MarkdownRendererProps) { + const prepared = prepareStatementSources(markdown, projectUuid, window.location.origin) return ( ( - - ), + a: ({ node: _node, href, children, ...props }) => { + const source = href ? prepared.sourceLinks.get(href) : undefined + return ( + + {source ? ( +