mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 09:33:46 +00:00
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:
@@ -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/>
|
||||
|
||||
Reference in New Issue
Block a user