const MAX_CAPTION = 120

/**
 * Für data-shinkan-exercise-media-caption: kurz, ohne Anführungszeichen/HTML.
 * @param {string|null|undefined} raw
 * @returns {string}
 */
export function sanitizeInlineMediaCaption(raw) {
  if (raw == null || typeof raw !== 'string') return ''
  let s = raw
    .replace(/[\u0000-\u001F\u007F]/g, ' ')
    .replace(/["'`<>]/g, ' ')
    .replace(/\s+/g, ' ')
    .trim()
  if (s.length > MAX_CAPTION) s = s.slice(0, MAX_CAPTION)
  return s
}
