import { Component, signal, computed, inject } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { MarkdownService } from '../../../../services/markdown.service'; import { HttpClient, HttpClientModule } from '@angular/common/http'; import { MarkdownViewerComponent } from '../../../../components/markdown-viewer/markdown-viewer.component'; const DEFAULT_MD_PATH = 'assets/samples/markdown-playground.md'; const DEFAULT_MD_PATH_ABS = '/assets/samples/markdown-playground.md'; @Component({ selector: 'app-markdown-playground', standalone: true, imports: [CommonModule, FormsModule, HttpClientModule, MarkdownViewerComponent], template: `

Markdown Playground

Page de test interne pour valider tous les formatages Markdown supportés par ObsiViewer.

Markdown Source

Preview

`, styles: [` :host { display: block; height: 100%; } textarea { tab-size: 2; } textarea::-webkit-scrollbar { width: 8px; height: 8px; } textarea::-webkit-scrollbar-track { background: transparent; } textarea::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.2); border-radius: 4px; } textarea::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.3); } .dark textarea::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); } .dark textarea::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.3); } `] }) export class MarkdownPlaygroundComponent { private markdownService = inject(MarkdownService); private http = inject(HttpClient); sample = signal(''); useComponentView = signal(true); renderedHtml = computed(() => { const markdown = this.sample(); try { return this.markdownService.render(markdown, [], undefined); } catch (error) { console.error('Markdown render error:', error); return `
Erreur de rendu: ${error}
`; } }); constructor() { this.loadDefaultSample(); } private loadDefaultSample(): void { this.http.get(DEFAULT_MD_PATH, { responseType: 'text' }).subscribe({ next: (text) => this.sample.set(text ?? ''), error: (err) => { console.warn('Fallback: retry loading default markdown via absolute path', err); this.http.get(DEFAULT_MD_PATH_ABS, { responseType: 'text' }).subscribe({ next: (text) => this.sample.set(text ?? ''), error: (err2) => { console.error('Failed to load default markdown (both paths):', err2); this.sample.set(''); } }); } }); } resetToDefault(): void { this.loadDefaultSample(); } toggleViewMode(): void { this.useComponentView.update(v => !v); } }