Opens external links in new windows

This commit is contained in:
Christophe HENRY 2021-04-02 23:48:02 +02:00
parent 9471816b1e
commit 6a8c220716
3 changed files with 10 additions and 8 deletions

View File

@ -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 .= "<p><a class='$protocol' href='$link'>$linkText</a></p>\n";
$output .= "<p><a {$newWindow}class='$protocol' href='$link'>$linkText</a></p>\n";
break;
case "#":
$title = $node["title"];

View File

@ -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;

View File

@ -1,6 +1,6 @@
<p>NOTE: this page was downloaded on 2021-03-04 from the original capsule</p>
<p><a class='gemini' href='gemini://gemini.circumlunar.space/docs/specification.gmi'>Gemini</a></p>
<p><a class='https' href='https://gemini.circumlunar.space/docs/specification.gmi'>Web</a></p>
<p><a target='_blank' class='gemini' href='gemini://gemini.circumlunar.space/docs/specification.gmi'>Gemini</a></p>
<p><a target='_blank' class='https' href='https://gemini.circumlunar.space/docs/specification.gmi'>Web</a></p>
<p><a class='local' href='specification_Gemini_v0.14.3.txt'>Copie locale texte</a></p>
<p>&nbsp;</p>
<h1>Project Gemini</h1>