All files / apps/wp-editor/server/utils blockMarkers.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 3/3
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 92x     2x 55x   2x 27x  
const MARKER = /<!--\s*(\/?)wp:([\w/-]+)(?:\s[^>]*?)?(\/?)-->/g;
 
/** The ordered `<!-- wp:… -->` sequence, attributes dropped, e.g. `paragraph`, `/paragraph`. */
export const blockMarkers = (html: string): string[] =>
    [...html.matchAll(MARKER)].map(([, close, name, self]) => `${close}${name}${self}`);
 
export const markersDiffer = (base: string, proposed: string): boolean =>
    blockMarkers(base).join("\n") !== blockMarkers(proposed).join("\n");