la mise en forme du texte est correct pour la description des romans
This commit is contained in:
parent
a2eac6f792
commit
be5dbbdbf2
76
roman.php
76
roman.php
@ -16,6 +16,80 @@ if (!$story) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Fonction pour convertir le contenu Delta en HTML
|
||||
function deltaToHtml($content) {
|
||||
if (empty($content)) return '';
|
||||
|
||||
// Si le contenu est déjà en HTML (ancien format)
|
||||
if (is_string($content) && !isJson($content)) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Convertir la chaîne JSON en tableau si nécessaire
|
||||
if (is_string($content)) {
|
||||
$delta = json_decode($content, true);
|
||||
} else {
|
||||
$delta = $content;
|
||||
}
|
||||
|
||||
if (!isset($delta['ops'])) return '';
|
||||
|
||||
$html = '';
|
||||
foreach ($delta['ops'] as $op) {
|
||||
if (is_string($op['insert'])) {
|
||||
$text = htmlspecialchars($op['insert']);
|
||||
|
||||
// Gérer les styles de texte
|
||||
if (isset($op['attributes'])) {
|
||||
if (!empty($op['attributes']['bold'])) {
|
||||
$text = "<strong>{$text}</strong>";
|
||||
}
|
||||
if (!empty($op['attributes']['italic'])) {
|
||||
$text = "<em>{$text}</em>";
|
||||
}
|
||||
if (!empty($op['attributes']['underline'])) {
|
||||
$text = "<u>{$text}</u>";
|
||||
}
|
||||
// Ajouter d'autres styles si nécessaire
|
||||
}
|
||||
|
||||
// Convertir les retours à la ligne en paragraphes
|
||||
if ($text === "\n") {
|
||||
$html .= "<br>";
|
||||
} else {
|
||||
$html .= $text;
|
||||
}
|
||||
}
|
||||
// Gérer les images
|
||||
elseif (is_array($op['insert']) && isset($op['insert']['image'])) {
|
||||
$imageUrl = $op['insert']['image'];
|
||||
error_log('URL originale: ' . $imageUrl);
|
||||
// Retirer tous les "../" au début de l'URL
|
||||
$imageUrl = preg_replace('/^(?:\.\.\/)+/', '', $imageUrl);
|
||||
error_log('URL nettoyée: ' . $imageUrl);
|
||||
$html .= "<img src=\"{$imageUrl}\" alt=\"Image du chapitre\">";
|
||||
}
|
||||
}
|
||||
|
||||
// Envelopper le contenu dans des balises p si nécessaire
|
||||
if (!empty($html)) {
|
||||
$paragraphs = explode("\n\n", $html);
|
||||
$html = '';
|
||||
foreach ($paragraphs as $p) {
|
||||
if (trim($p) !== '') {
|
||||
$html .= "<p>{$p}</p>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
function isJson($string) {
|
||||
json_decode($string);
|
||||
return json_last_error() === JSON_ERROR_NONE;
|
||||
}
|
||||
|
||||
$config = Config::load();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
@ -45,7 +119,7 @@ $config = Config::load();
|
||||
<!-- Contenu principal -->
|
||||
<div class="novel-content">
|
||||
<div class="novel-description">
|
||||
<?= $story['description'] ?>
|
||||
<?= deltaToHtml($story['description']) ?>
|
||||
</div>
|
||||
|
||||
<aside class="chapters-menu">
|
||||
|
Loading…
x
Reference in New Issue
Block a user