Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/carta-md/src/lib/internal/speculative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const clonePosition = (position: Position): Position => {
};
};

/** Escape text so it is parsed as text, and not as markup, by the overlay. */
const escapeHtml = (text: string): string =>
text.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');

/**
* Temporary updates the highlight overlay to reflect the changes between two text strings,
* waiting for the actual update to be applied. This way, the user can immediately see the changes,
Expand All @@ -32,7 +36,7 @@ export function speculativeHighlightUpdate(from: string, to: string, currentHTML
let writingPosition: Position = { line: 0, span: 0, char: 0 };
let readingPosition: Position = { line: 0, span: 0, char: 0 };

if (lines.length === 0) return to;
if (lines.length === 0) return escapeHtml(to);

const advance = () => {
writingPosition = clonePosition(readingPosition);
Expand Down
Loading