pediatric-ai-scribe-v3/client
Daniel 12eaf57ddb feat(client): Learning Hub — sanitized HTML body + Marp slide viewer
Closes the last two Learning Hub follow-ups flagged in the earlier
commit body: rich-HTML body rendering (instead of pre-wrap plain text)
and in-React Marp slide playback (instead of the legacy-viewer link).

client/src/lib/sanitize.ts (new)
  Inline HTML sanitizer. Parses via DOMParser (sandboxed — no scripts
  run), walks the tree and:
    • Removes script / style / iframe / object / embed / link / meta /
      base / form / input / button / select / textarea.
    • Drops every on* event-handler attribute.
    • Drops href / src / xlink:href values starting with javascript:
      or data:text/html.
    • Drops any attribute whose value contains "javascript:".
    • Falls back to entity-escaping the raw string if parsing throws.
  Admin-authored Learning Hub content is the trust model here —
  essentially CMS content. A full DOMPurify dep would be strictly
  better but adding a package requires a network install; the inline
  sanitizer covers the realistic XSS vectors without the dep bump.

client/src/pages/Learning.tsx
  • Body rendering (non-presentation content_type) now runs through
    sanitizeHtml + dangerouslySetInnerHTML with a `prose prose-sm`
    Tailwind-typography class. Markdown/HTML formatting from admin
    content now appears correctly (headings, lists, code, bold,
    italics, links) instead of raw text.
  • SlideViewer component (new) replaces the "Open in legacy viewer"
    button for content_type === 'presentation'. Fetches
    /api/learning/content/:slug/slides (returns { css, slides[] } —
    server-side Marp output), sanitizes each slide's HTML + the CSS
    block, renders one slide at a time with:
      - prev/next buttons
      - keyboard ←/→ and PageUp/PageDown navigation
      - slide counter (N/total)
      - fullscreen toggle (Escape exits)
    Marp's own CSS is injected scoped-ish via sanitizer so slide
    theming survives.

shared/types.ts + client/src/shared/types.ts — additive:
  LearningSlidesOk { css: string; slides: string[] }

Client tsc + vite build clean. Initial bundle unchanged
(342.86 kB / 106.03 kB gz) since Learning.tsx was already lazy-loaded;
the sanitizer + SlideViewer roll into its chunk.
2026-04-24 02:30:44 +02:00
..
public feat(client): day 6 — scaffold React 19 + Vite + Tailwind v4 + shadcn/ui 2026-04-23 21:58:37 +02:00
src feat(client): Learning Hub — sanitized HTML body + Marp slide viewer 2026-04-24 02:30:44 +02:00
.gitignore feat(client): day 6 — scaffold React 19 + Vite + Tailwind v4 + shadcn/ui 2026-04-23 21:58:37 +02:00
components.json feat(client): day 6 — scaffold React 19 + Vite + Tailwind v4 + shadcn/ui 2026-04-23 21:58:37 +02:00
eslint.config.js feat(client): day 6 — scaffold React 19 + Vite + Tailwind v4 + shadcn/ui 2026-04-23 21:58:37 +02:00
index.html feat(client): day 6 — scaffold React 19 + Vite + Tailwind v4 + shadcn/ui 2026-04-23 21:58:37 +02:00
package-lock.json feat: day 7 — first tab ported to React (Extensions) + Express serves /app/* 2026-04-23 22:09:04 +02:00
package.json feat(client): port age→weight + BSA + dose + GCS; shared/clinical module 2026-04-24 01:11:58 +02:00
README.md feat(client): day 6 — scaffold React 19 + Vite + Tailwind v4 + shadcn/ui 2026-04-23 21:58:37 +02:00
tsconfig.app.json feat(client): port age→weight + BSA + dose + GCS; shared/clinical module 2026-04-24 01:11:58 +02:00
tsconfig.json feat(client): day 6 — scaffold React 19 + Vite + Tailwind v4 + shadcn/ui 2026-04-23 21:58:37 +02:00
tsconfig.node.json feat(client): day 6 — scaffold React 19 + Vite + Tailwind v4 + shadcn/ui 2026-04-23 21:58:37 +02:00
vite.config.ts feat(client): day 6 — scaffold React 19 + Vite + Tailwind v4 + shadcn/ui 2026-04-23 21:58:37 +02:00

React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

React Compiler

The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see this documentation.

Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:

export default defineConfig([
  globalIgnores(['dist']),
  {
    files: ['**/*.{ts,tsx}'],
    extends: [
      // Other configs...

      // Remove tseslint.configs.recommended and replace with this
      tseslint.configs.recommendedTypeChecked,
      // Alternatively, use this for stricter rules
      tseslint.configs.strictTypeChecked,
      // Optionally, add this for stylistic rules
      tseslint.configs.stylisticTypeChecked,

      // Other configs...
    ],
    languageOptions: {
      parserOptions: {
        project: ['./tsconfig.node.json', './tsconfig.app.json'],
        tsconfigRootDir: import.meta.dirname,
      },
      // other options...
    },
  },
])

You can also install eslint-plugin-react-x and eslint-plugin-react-dom for React-specific lint rules:

// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'

export default defineConfig([
  globalIgnores(['dist']),
  {
    files: ['**/*.{ts,tsx}'],
    extends: [
      // Other configs...
      // Enable lint rules for React
      reactX.configs['recommended-typescript'],
      // Enable lint rules for React DOM
      reactDom.configs.recommended,
    ],
    languageOptions: {
      parserOptions: {
        project: ['./tsconfig.node.json', './tsconfig.app.json'],
        tsconfigRootDir: import.meta.dirname,
      },
      // other options...
    },
  },
])