From c970291049ac0114f3042a2b29aa0cca4ec37f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Thu, 10 Apr 2025 08:49:24 +0400 Subject: [PATCH] parse markdown --- css/video-page.css | 74 ++++++++++++++++++++++++++++++++++++++- includes/lib/markdown.php | 43 +++++++++++++++++++++++ video.php | 8 +++-- 3 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 includes/lib/markdown.php diff --git a/css/video-page.css b/css/video-page.css index 7b3cbd4..b96ee81 100644 --- a/css/video-page.css +++ b/css/video-page.css @@ -236,7 +236,79 @@ line-height: 1.6; margin-bottom: 1.5rem; color: #333; - white-space: pre-line; +} + +/* Styles pour les éléments Markdown dans la description */ +.video-description p { + margin-bottom: 1rem; +} + +.video-description ol, +.video-description ul { + margin-bottom: 1rem; + padding-left: 1.5rem; +} + +.video-description li { + margin-bottom: 0.5rem; +} + +.video-description a { + color: var(--primary-red); + text-decoration: none; + transition: color 0.2s; +} + +.video-description a:hover { + text-decoration: underline; +} + +.video-description blockquote { + border-left: 4px solid #e0e0e0; + padding-left: 1rem; + margin-left: 0; + margin-right: 0; + margin-bottom: 1rem; + color: #555; + font-style: italic; +} + +.video-description code { + background-color: #f5f5f5; + padding: 0.2rem 0.4rem; + border-radius: 3px; + font-family: monospace; + font-size: 0.875rem; +} + +.video-description pre { + background-color: #f5f5f5; + padding: 1rem; + border-radius: 4px; + overflow-x: auto; + margin-bottom: 1rem; +} + +.video-description pre code { + background-color: transparent; + padding: 0; + border-radius: 0; + display: block; + white-space: pre; +} + +.video-description hr { + border: 0; + height: 1px; + background-color: #e0e0e0; + margin: 2rem 0; +} + +.video-description .markdown-image { + max-width: 100%; + height: auto; + border-radius: 4px; + margin: 1rem 0; } .truncated-description, .full-description { diff --git a/includes/lib/markdown.php b/includes/lib/markdown.php new file mode 100644 index 0000000..505430e --- /dev/null +++ b/includes/lib/markdown.php @@ -0,0 +1,43 @@ +$1', $markdown); + $markdown = preg_replace('/\*(.*?)\*/s', '$1', $markdown); + + // Conversion des listes à puces + $markdown = preg_replace('/^- (.*?)$/m', '
  • $1
  • ', $markdown); + $markdown = preg_replace('/(
  • .*?<\/li>\n?)+/s', '', $markdown); + + // Conversion des listes numérotées + $markdown = preg_replace('/^\d+\. (.*?)$/m', '
  • $1
  • ', $markdown); + $markdown = preg_replace('/(
  • .*?<\/li>\n?)+/s', '
      $0
    ', $markdown); + + // Conversion des liens [texte](url) + $markdown = preg_replace('/\[([^\]]+)\]\(([^)]+)\)/', '$1', $markdown); + + // Détection et conversion des URLs brutes en liens cliquables + $urlPattern = '/(https?:\/\/[^\s<]+[^\s<\.)])/i'; + $markdown = preg_replace($urlPattern, '$1', $markdown); + + // Gestion des retours à la ligne + $markdown = nl2br($markdown); + + // Nettoyage des balises br dans les listes + $markdown = preg_replace('/<\/li>
    /', '
  • ', $markdown); + + return $markdown; +} \ No newline at end of file diff --git a/video.php b/video.php index 22825d3..502a9d3 100644 --- a/video.php +++ b/video.php @@ -1,6 +1,8 @@
    - +
    - +