From 9fa5c6d88f914c4c0da4a49e6dff928b6b0aa8e7 Mon Sep 17 00:00:00 2001 From: achmizs <1874748+achmizs@users.noreply.github.com> Date: Sun, 5 Dec 2021 18:46:27 -0500 Subject: [PATCH] Minor code cleanup --- pastebin-embed.php | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/pastebin-embed.php b/pastebin-embed.php index f95fb7c..bb5bae0 100644 --- a/pastebin-embed.php +++ b/pastebin-embed.php @@ -4,10 +4,10 @@ * \Licensed under the MIT License * \brief Embed Pastebin pastes in a wikipage. */ -$RecipeInfo['PastebinEmbed']['Version'] = '2018-10-19'; +$RecipeInfo['PastebinEmbed']['Version'] = '2021-12-05'; ## (:pastebin-embed:) -Markup('pastebin-embed', ' $line_range) { if (preg_match("/([0-9]+)[-–]([0-9]+)/", $line_range, $m)) { @@ -43,8 +45,10 @@ function PastebinEmbed ($m) { } ## Same thing, but for highlighted line ranges. - $hl_line_ranges = $parsed['hl'] ? explode(',', $parsed['hl']) : array(); - $hl_line_numbers = array(); + $hl_line_ranges = $parsed['hl'] + ? explode(',', $parsed['hl']) + : [ ]; + $hl_line_numbers = [ ]; $hl_to_end_from = -1; foreach ($hl_line_ranges as $key => $hl_line_range) { if (preg_match("/([0-9]+)[-–]([0-9]+)/", $hl_line_range, $m)) { @@ -62,14 +66,14 @@ function PastebinEmbed ($m) { $out = "Unknown error."; - ## There are three 'modes': raw (retrieve just the text, client-side, and insert it + ## There are three ‘modes’: raw (retrieve just the text, client-side, and insert it ## into the page), no-js (retrieve the HTML, server-side, and insert it into the - ## page), and default (i.e., JS-based - insert the scriptlet, and let it retrieve and + ## page), and default (i.e., JS-based: insert the scriptlet, and let it retrieve and ## insert the HTML into the page, client-side & async). ## The mode is set by arguments to the (:pastebin-embed:) markup: - ## - if neither the 'raw' nor the 'no-js' option is given, default (JS) mode is used - ## - if the 'raw' option is given, raw mode is used - ## - if the 'no-js' option is given, no-js mode is used + ## - if neither the ‘raw’ nor the ‘no-js’ option is given, default (JS) mode is used + ## - if the ‘raw’ option is given, raw mode is used + ## - if the ‘no-js’ option is given, no-js mode is used if ($raw) { $raw_text = file_get_contents($embed_raw_url); if (!$raw_text) return Keep("Could not retrieve paste!"); @@ -96,8 +100,10 @@ function PastebinEmbed ($m) { } $raw_text = implode("\n", $raw_lines); - ## The 'no-pre' option means we shouldn't wrap the text in a
 tag.
-		$out = $noPre ? $raw_text : Keep("
\n" . $raw_text . "\n
\n"); + ## The ‘no-pre’ option means we shouldn’t wrap the text in a
 tag.
+		$out = $noPre 
+			   ? $raw_text 
+			   : Keep("
\n" . $raw_text . "\n
\n"); } else if ($noJS) { include_once('simple_html_dom.php'); @@ -141,7 +147,8 @@ function PastebinEmbed ($m) { } else { $out = Keep(""); - if (!empty($hl_line_numbers) || !empty($line_numbers)) { + if ( !empty($hl_line_numbers) + || !empty($line_numbers)) { $line_numbers_js = "[ ".implode(", ",$line_numbers)." ]"; $hl_line_numbers_js = "[ ".implode(", ",$hl_line_numbers)." ]"; $out .= Keep("