;
if (/^\s*```/.test(plain)) { fenced = !fenced; return
{plain ? marks(line) : null}
; }
if (fenced) return
{plain ? marks(line) : }
;
const heading = /^(#{1,6})\s+/.exec(plain);
if (heading) return
{marks(stripLead(line, heading[0].length))}
;
const item = /^(\s*)([-*+]|\d+[.)])\s+/.exec(plain);
if (item) return
{marks(stripLead(line, item[0].length))}
;
return
{plain ? marks(line) : }
;
})}
;
}
/** Drop the first `count` characters (the Markdown marker) from the front of a line of segments. */
function stripLead(line: Segment[], count: number): Segment[] {
const out: Segment[] = []; let left = count;
for (const seg of line) {
if (left >= seg.text.length) { left -= seg.text.length; continue; }
out.push({ text: seg.text.slice(left), changed: seg.changed }); left = 0;
}
return out;
}
function DiffView({ original, updated }: { original: string; updated: string }) {
const rows = useMemo(() => lineDiff(original, updated), [original, updated]);
const stats = diffStats(rows);
return
{/* The page may run its own scripts in an isolated frame; the policy inside blocks every outside request. */}
{file.status === 'added' ?
{tr("Not there before.")}
: }
{file.status === 'removed' ?
{tr("Removed.")}
: }
{needsOutsideFiles(updated) ?
{tr("This page asks for files from the internet, which the preview does not load, so it may look incomplete. View code shows exactly what was written.")}
: null}>}
>;
if (words) return <>{heads}
>;
return ;
}
/**
* The finished A versus B, in one window of a fixed, modest size whatever was made: text and Markdown rendered with the changed words marked,
* a web page as two sandboxed previews (with a code toggle), pictures side by side to enlarge, anything else as a diff, and a compact switcher
* when several files changed. It scrolls inside itself; it never grows to fill the screen.
*/
export function TimeSkipCompare({ jobId, files, more = 0 }: { jobId: string; files: TimeSkipFile[]; more?: number }) {
const [at, setAt] = useState(0);
useEffect(() => { setAt(0); }, [jobId]);
const file = files[Math.min(at, files.length - 1)];
if (!file) return null;
return
{files.length > 1 ?