From 3701eca5e7476a37e8884024adecac60ffc3fc48 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 9 Jul 2026 09:22:12 -0700 Subject: [PATCH] Add link rendering and transforming to docs --- README.md | 2 +- includes/qi.php | 21 ++++++++++++++++++++- modules/qi_docs.php | 4 +++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 76c249e0..ef2f04da 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Downloaded styles can be unzipped into `customisations/` and mounted into boards php bin/qi style:mount test customisations/stylename ``` -See the complete [QuickInstall CLI docs](index.php?page=cli). +See the complete [QuickInstall CLI docs](docs/sandbox-cli.md). ## 🐞 Support You can receive support at the [phpBB3 QuickInstall Discussion/Support](https://www.phpbb.com/customise/db/official_tool/phpbb3_quickinstall/support) forum. diff --git a/includes/qi.php b/includes/qi.php index 7080b8d0..f0a81151 100644 --- a/includes/qi.php +++ b/includes/qi.php @@ -162,8 +162,13 @@ public static function lang_key_exists($key) return isset($user->lang[$key]); } - public static function render_markdown($doc_body, $anchor_prefix = '') + public static function render_markdown($doc_body, $anchor_prefix = '', array $link_rewrites = array()) { + if (!empty($link_rewrites)) + { + $doc_body = self::rewrite_markdown_links($doc_body, $link_rewrites); + } + if ($anchor_prefix !== '') { $doc_body = self::add_markdown_anchors($doc_body, $anchor_prefix); @@ -184,6 +189,20 @@ public static function render_markdown($doc_body, $anchor_prefix = '') ); } + private static function rewrite_markdown_links($doc_body, array $link_rewrites) + { + return preg_replace_callback('/\]\(([^)\s]+)\)/', function ($matches) use ($link_rewrites) { + $url = $matches[1]; + + if (!isset($link_rewrites[$url])) + { + return $matches[0]; + } + + return '](' . $link_rewrites[$url] . ')'; + }, $doc_body); + } + public static function get_markdown_anchors($doc_body, $prefix) { $links = array(); diff --git a/modules/qi_docs.php b/modules/qi_docs.php index 7e72927b..c9626054 100644 --- a/modules/qi_docs.php +++ b/modules/qi_docs.php @@ -20,7 +20,9 @@ public function run() $doc_file = $quickinstall_path . 'README.md'; if (file_exists($doc_file)) { - $doc_body = qi::render_markdown(file_get_contents($doc_file), 'readme'); + $doc_body = qi::render_markdown(file_get_contents($doc_file), 'readme', array( + 'docs/sandbox-cli.md' => 'index.php?page=cli', + )); $template->assign_var('DOC_BODY', $doc_body); }