From 6a8c220716208a849b130c73b87c9af16aadcb53 Mon Sep 17 00:00:00 2001 From: Christophe HENRY Date: Fri, 2 Apr 2021 23:48:02 +0200 Subject: [PATCH] Opens external links in new windows --- lib-htmgem.inc.php | 10 ++++++---- tests/cli/translate_to_html.php | 4 ++-- tests/files_with_html/text.gmi.html | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib-htmgem.inc.php b/lib-htmgem.inc.php index da4449f..6ad1ed3 100644 --- a/lib-htmgem.inc.php +++ b/lib-htmgem.inc.php @@ -341,16 +341,18 @@ class GemtextTranslate_html { if ($textDecoration) self::addTextDecoration($linkText); } preg_match("/^([^:]+):/", $link, $matches); - $protocol = @$matches[1]; - if (empty($protocol)) { - $protocol = "local"; + $protocol = @$matches[1]??"local"; + if ("local"==$protocol) { if (!is_null($this->baseUrl)) { // No URL rewriting if ($link[0]!="/") $link = "{$this->baseUrl}/$link"; $link = self::resolve_path($link); $link = "/htmgem/index.php?url=$link"; } + $newWindow = ""; + } else { + $newWindow = "target='_blank' "; } - $output .= "

$linkText

\n"; + $output .= "

$linkText

\n"; break; case "#": $title = $node["title"]; diff --git a/tests/cli/translate_to_html.php b/tests/cli/translate_to_html.php index 6905211..72d3a92 100644 --- a/tests/cli/translate_to_html.php +++ b/tests/cli/translate_to_html.php @@ -5,5 +5,5 @@ $fileName = $argv[1]; require_once dirname(__FILE__)."/../../lib-htmgem.inc.php"; $text = file_get_contents($fileName); -$gt_gemtext = new \htmgem\GemtextTranslate_html($text); -echo strval($gt_gemtext); +$gt_html = new \htmgem\GemtextTranslate_html($text); +echo $gt_html->translatedGemtext; diff --git a/tests/files_with_html/text.gmi.html b/tests/files_with_html/text.gmi.html index 423d5b0..4f3b03d 100644 --- a/tests/files_with_html/text.gmi.html +++ b/tests/files_with_html/text.gmi.html @@ -1,6 +1,6 @@

NOTE: this page was downloaded on 2021-03-04 from the original capsule

-

Gemini

-

Web

+

Gemini

+

Web

Copie locale texte

 

Project Gemini