Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

16 lines
557 B
TypeScript
Raw Permalink Normal View History

2025-12-12 14:26:25 +09:00
function escapePipesOutsideBackticks(value: string): string {
// Split into chunks that are either code spans or normal text.
// Capturing group keeps the code chunks in the array.
return value
.split(/(`[^`]*`)/g)
.map((chunk) => (chunk.startsWith('`') ? chunk : chunk.replace(/\|/g, '\\|')))
.join('');
}
export default function escapeCell(value: string): string {
// As the pipe is use for the table structure
const newValue = escapePipesOutsideBackticks(value);
return newValue.replace(/</g, '&lt;').replace(/`&lt;/g, '`<');
}