From bfbd104d492412244428d693286db51a91276c16 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Sat, 9 Aug 2025 22:54:38 +0100 Subject: [PATCH] Convert markdown to HTML using PHP in version dialog Replaces client-side JavaScript markdown conversion with server-side PHP processing for release notes. Markdown is now parsed and rendered as HTML directly in PHP, improving reliability and removing the dependency on the Showdown library. --- application/views/version_dialog/index.php | 100 ++++++++++++--------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/application/views/version_dialog/index.php b/application/views/version_dialog/index.php index 6d70492f..b84a8fae 100644 --- a/application/views/version_dialog/index.php +++ b/application/views/version_dialog/index.php @@ -9,39 +9,7 @@ - - - optionslib) ? $this->optionslib->get_option('version_dialog') : 'release_notes'; if ($versionDialogMode == 'custom_text' || $versionDialogMode == 'both') { ?> @@ -75,22 +43,72 @@ $data = json_decode($response, true); $current_version = $this->optionslib->get_option('version'); + if ($data !== null && !empty($data)) { + $firstRelease = null; foreach ($data as $singledata) { if ($singledata['tag_name'] == $current_version) { $firstRelease = $singledata; - continue; + break; } } - $releaseBody = isset($firstRelease['body']) ? $firstRelease['body'] : 'No release information available'; - $htmlReleaseBody = htmlspecialchars($releaseBody); - $htmlReleaseBodyWithLinks = preg_replace('/(https?:\/\/[^\s<]+)/', '$1', $htmlReleaseBody); + if ($firstRelease !== null) { + $releaseBody = isset($firstRelease['body']) ? $firstRelease['body'] : 'No release information available'; - $releaseName = isset($firstRelease['name']) ? $firstRelease['name'] : 'No version name information available'; - echo "

v" . $releaseName . "

"; - echo ""; - echo "
"; + $releaseName = isset($firstRelease['name']) ? $firstRelease['name'] : 'No version name information available'; + echo "

v" . $releaseName . "

"; + + // Convert markdown to HTML using PHP + $htmlContent = $releaseBody; + + // Escape HTML first to prevent issues + $htmlContent = htmlspecialchars($htmlContent); + + // Convert headers + $htmlContent = preg_replace('/^## (.+)$/m', '

$1

', $htmlContent); + $htmlContent = preg_replace('/^# (.+)$/m', '

$1

', $htmlContent); + + // Convert bullet points to list items + // First, find all bullet point sections and convert them to proper lists + $htmlContent = preg_replace_callback( + '/(?:^[ ]*\* .+(?:\r?\n|$))+/m', + function($matches) { + $listContent = $matches[0]; + // Convert each bullet point to
  • , removing any trailing newlines + $listContent = preg_replace('/^[ ]*\* (.+?)(?:\r?\n|$)/m', '
  • $1
  • ', $listContent); + // Wrap in