fix: ordered list numbering in Info page shows correct sequence

Each numbered rule (1, 2, 3...) was rendered as separate <ol> elements
all starting from 1. Added start attribute to preserve original numbering
and allowed it through DOMPurify sanitization.
This commit is contained in:
Fringg
2026-03-04 04:49:40 +03:00
parent a3ddddfa8c
commit 8157ca5f02

View File

@@ -100,7 +100,7 @@ const sanitizeHtml = (html: string): string => {
'div',
'tg-spoiler',
],
ALLOWED_ATTR: ['href', 'target', 'rel', 'class'],
ALLOWED_ATTR: ['href', 'target', 'rel', 'class', 'start'],
ALLOW_DATA_ATTR: false,
});
};
@@ -135,12 +135,13 @@ const formatContent = (content: string): string => {
if (/^[-•]\s/.test(trimmed) || /^\d+[.)]\s/.test(trimmed)) {
const lines = trimmed.split('\n');
const isOrdered = /^\d+[.)]\s/.test(lines[0]);
const startNum = isOrdered ? parseInt(lines[0].match(/^(\d+)/)?.[1] || '1', 10) : 1;
const listItems = lines
.map((line) => line.replace(/^[-•]\s*/, '').replace(/^\d+[.)]\s*/, ''))
.filter((line) => line.trim())
.map((line) => `<li>${line}</li>`)
.join('');
return isOrdered ? `<ol>${listItems}</ol>` : `<ul>${listItems}</ul>`;
return isOrdered ? `<ol start="${startNum}">${listItems}</ol>` : `<ul>${listItems}</ul>`;
}
// Regular paragraph — single newlines become <br/>