body-prettier
Some checks failed
Deploy on push / deploy (push) Failing after 5s

This commit is contained in:
2025-07-25 09:03:11 +03:00
parent 0f16679a06
commit 472b24527a
4 changed files with 51 additions and 4 deletions

View File

@@ -429,7 +429,6 @@ const ShoutsRoute = (props: ShoutsRouteProps) => {
>
<div style="padding: 1rem;">
<HTMLEditor value={selectedMediaBody()} onInput={(value) => setSelectedMediaBody(value)} />
gjl
</div>
</Modal>
</div>

View File

@@ -127,8 +127,11 @@ const HTMLEditor = (props: HTMLEditorProps) => {
}
if (value.trim()) {
// Форматируем HTML перед экранированием
const formattedValue = formatHTML(value)
// Экранируем HTML для безопасности
const escapedValue = value
const escapedValue = formattedValue
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
@@ -329,6 +332,24 @@ const HTMLEditor = (props: HTMLEditorProps) => {
}, 10)
}
const formatHTML = (html: string): string => {
try {
// Простое форматирование с отступами
const lines = html.split(/\n/)
const formattedLines = lines.map((line, index) => {
const trimmedLine = line.trim()
if (trimmedLine.startsWith('<') && !trimmedLine.startsWith('</')) {
return ' '.repeat(index > 0 ? 1 : 0) + trimmedLine
}
return trimmedLine
})
return formattedLines.join('\n')
} catch (error) {
console.warn('HTML formatting error:', error)
return html
}
}
return (
<div
ref={editorElement}