/** * Accessibility post-processing for marked-generated markdown HTML. * * axe flags two issues on rendered markdown that we fix here rather than in the * source content: * - `scrollable-region-focusable`:
 and  blocks can overflow on the
 *    x-axis, so they must be keyboard focusable to let keyboard users scroll them.
 *  - `label`: GitHub-style task-list checkboxes (`- [ ]` / `- [x]`) render as bare
 *    disabled  elements with no accessible name.
 *
 * This module is pure (no DOM or node deps) so it can run both at build time
 * (src/lib/detail-page.ts) and on the client (src/scripts/pages/file-browser.ts).
 */
export function enhanceMarkdownA11y(html: string): string {
  if (!html) return html;
  let out = html;

  // Make scrollable code/table blocks keyboard focusable.
  out = out.replace(/]*\btabindex=)/g, '
]*\btabindex=)/g, '
]*\btype="checkbox"[^>]*)>/g, (match, attrs) => { if (/\baria-label=/.test(attrs)) return match; const label = /\bchecked\b/.test(attrs) ? "Completed task" : "Incomplete task"; return ``; } ); return out; }