${escaped}`
+ }
+}
+
+function loadSamplesForFile(mdRelativePath: string): RenderedSample[] {
+ const jsonPath = resolve(SAMPLES_DIR, mdRelativePath.replace(/\.md$/, '.json'))
+ if (fileCache.has(jsonPath)) return fileCache.get(jsonPath)!
+ if (!existsSync(jsonPath)) { fileCache.set(jsonPath, []); return [] }
+ try {
+ const data = JSON.parse(readFileSync(jsonPath, 'utf-8')) as RenderedSample[]
+ fileCache.set(jsonPath, data)
+ return data
+ } catch {
+ fileCache.set(jsonPath, [])
+ return []
+ }
+}
+
+function computeStableKey(snippet: string, setup?: string | null): string {
+ const input = snippet + '\0' + (setup ?? '')
+ return createHash('sha256').update(input).digest('hex').slice(0, 12).toLowerCase()
+}
+
+function escapeAttr(str: string): string {
+ return str.replace(/&/g, '&').replace(/"/g, '"').replace(//g, '>')
+}
+
+function buildPlaygroundUrl(snippet: string, setup?: string | null): string {
+ const params = new URLSearchParams()
+ params.set('snippet', Buffer.from(snippet).toString('base64url'))
+ if (setup) params.set('setup', Buffer.from(setup).toString('base64url'))
+ params.set('scenario', 'webshop')
+ return `${BASE_PATH}playground-editor#${params.toString()}`
+}
+
+export function expressiveSamplePlugin(md: MarkdownIt): void {
+ const originalParse = md.parse.bind(md)
+
+ md.parse = function (src: string, env: any): any[] {
+ const relativePath: string | undefined = env?.relativePath
+ if (!relativePath) return originalParse(src, env)
+
+ const samples = loadSamplesForFile(relativePath)
+ const lines = src.split('\n')
+ const result: string[] = []
+ let i = 0
+
+ while (i < lines.length) {
+ const trimmed = lines[i].trimStart()
+ if (!trimmed.startsWith('::: expressive-sample')) {
+ result.push(lines[i])
+ i++
+ continue
+ }
+
+ i++
+ const bodyLines: string[] = []
+ while (i < lines.length) {
+ const closeTrimmed = lines[i].trimStart()
+ if (closeTrimmed === ':::') break
+ bodyLines.push(lines[i])
+ i++
+ }
+ i++ // skip closing :::
+
+ const body = bodyLines.join('\n').trim()
+ const sepIdx = body.indexOf(SETUP_SEPARATOR)
+
+ let snippet: string
+ let setup: string | undefined
+
+ if (sepIdx >= 0) {
+ snippet = body.slice(0, sepIdx).trim()
+ setup = body.slice(sepIdx + SETUP_SEPARATOR.length).trim()
+ } else {
+ snippet = body
+ }
+
+ const key = computeStableKey(snippet, setup)
+ const sample = samples.find(s => s.key === key)
+
+ if (sample) {
+ // C# code (snippet + optional setup) — pre-highlighted, always visible
+ let csharpContent = sample.snippet
+ if (sample.setup) {
+ csharpContent += '\n\n// Setup\n' + sample.setup
+ }
+ const csharpHtml = highlight(csharpContent, 'csharp')
+
+ // Output tabs
+ const outputTabs: HighlightedTab[] = []
+ for (const targetId of ['sqlite', 'postgres', 'sqlserver', 'cosmos', 'mongodb', 'generator']) {
+ const target = sample.targets[targetId]
+ if (target) {
+ outputTabs.push({
+ id: targetId,
+ label: target.label,
+ html: target.isError
+ ? `${target.output.replace(/&/g, '&').replace(//g, '>')}`
+ : highlight(target.output, target.language),
+ isError: target.isError,
+ })
+ }
+ }
+
+ const playgroundUrl = buildPlaygroundUrl(snippet, setup)
+ const tabsBase64 = Buffer.from(JSON.stringify(outputTabs)).toString('base64')
+ const csharpBase64 = Buffer.from(csharpHtml).toString('base64')
+
+ result.push('')
+ result.push(
+ `@_initError+ } +} +else +{ +
@_result.ErrorMessage+ } + @if (_result.Diagnostics.Count > 0) + { +