All files / scripts/validators/executive-brief-translations strippers.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27                                89x   89x 177x 177x       89x    
/**
 * @module scripts/validators/executive-brief-translations/strippers
 * @description Strip fenced code blocks and HTML comments so other
 *              regexes don't false-match inside them.
 *
 *              Rule census: extracted from
 *              `scripts/validate-executive-brief-translations.ts` lines
 *              129–140. Logic is byte-identical to the original.
 *
 * @author Hack23 AB
 * @license Apache-2.0
 */
 
/** Strip fenced code blocks and HTML comments so other regexes don't false-match inside them. */
export function stripFencesAndComments(md: string): string {
  // Loop until stable to handle any nested/escaped occurrences.
  let result = md;
  let prev: string;
  do {
    prev = result;
    result = result
      .replace(/```[\s\S]*?```/g, '')
      .replace(/<!--[\s\S]*?-->/g, '');
  } while (result !== prev);
  return result;
}