Compare commits

..

No commits in common. "b7276e12e36501a00887fcf58888a0caac8fdd26" and "f29cf3a47629ed0d2071d6af9154a6cbe4c4b08b" have entirely different histories.

5 changed files with 43 additions and 36 deletions

View File

@ -6,12 +6,16 @@ All notable changes to this project will be documented in this file.
## [Unreleased] v3
* cgi-bin? Handle user input
* Handle client certificates?
* Page caching: dont generate twice an unmodified file.
* Separate project? Blog infrastructure with templates, style and RSS generator.
* Proxy for remote and local servers.
* Be able to move /htmgem anywhere and (for the Php part) outside the webbrowser scope.
## [Unreleased] v2
### Security
* Check url encoding: The filename fetched on disk may differ from that was asked by URL.
* Check unicode capability, UTF16 input, RTL/LTR, etc…
* Manage different type of carriage return: CR CR/LF LF.
@ -26,9 +30,10 @@ All notable changes to this project will be documented in this file.
## [Unreleased] v1
### Security
* Check url encoding: The filename fetched on disk may differ from that was asked by URL.
### Development
* Command line API for script, testing, CI…
* Automated tests like phpunit
### User interface

View File

@ -95,6 +95,7 @@ a.mailto:before {
}
pre {
margin: 0 -1rem;
overflow-x: auto;
}

View File

@ -15,8 +15,8 @@ Gemini est un nouveau protocole internet qui :
```
=> https://gemini.circumlunar.space/
=> https://tildegit.org/sbgodin/HtmGem/archive/master.zip Téléchargez la branche courante pour linstaller
=> https://tildegit.org/Sbgodin/htmgem Code source, rapports de bug, commentaires…
=> https://framagit.org/Sbgodin/htmgem/-/archive/master/htmgem-master.zip Téléchargez htmgem-master.zip pour linstaller
=> https://framagit.org/Sbgodin/htmgem Code source, rapports de bug, commentaires…
=> https://gmi.sbgodin.fr/htmgem Page principale de HtmGem via le web
=> gemini://gmi.sbgodin.fr/htmgem Page principale de HtmGem via Gemini

View File

@ -27,6 +27,7 @@ $documentRoot = $_SERVER['DOCUMENT_ROOT'];
$filePath = rtrim($_SERVER['DOCUMENT_ROOT'], "/")."/".ltrim($url, "/");
switch(true) {
case false:
case !realPath($filePath):
case !preg_match("/\.gmi$/", $url): # not finishing by .gmi
case strpos($filePath, $documentRoot)!==0: # not in web directory

View File

@ -107,49 +107,50 @@ class GemtextTranslate_gemtext {
}
protected function translate() {
$output = "";
ob_start();
foreach ($this->parsedGemtext as $node) {
$mode = $node["mode"];
switch($mode) {
case "":
$output .= $node["text"]."\n";
echo $node["text"]."\n";
break;
case "*":
foreach ($node["texts"] as $text) {
$output .= "* $text\n";
echo "* $text\n";
}
break;
case "```":
$output .= "```\n";
print("```\n");
foreach ($node["texts"] as $text) {
$output .= "$text\n";
echo "$text\n";
}
$output .= "```\n";
print("```\n");
break;
case ">":
foreach ($node["texts"] as $text) {
$output .= "> $text\n";
echo "> $text\n";
}
break;
case "=>":
$linkText = $node["text"];
if (!empty($linkText)) $linkText = " $linkText";
$output .= "=> ".$node["link"].$linkText."\n";
print("=> ".$node["link"].$linkText."\n");
break;
case "#":
case "##":
case "###":
$output .= "$mode ".$node["title"]."\n";
print("$mode ".$node["title"]."\n");
break;
case "^^^":
$output .= "^^^\n";
print("^^^\n");
break;
default:
die("Unknown mode: '{$node["mode"]}'\n");
}
}
$this->translatedGemtext = $output;
$this->translatedGemtext = ob_get_contents();
ob_end_clean();
}
public function __toString() {
@ -167,7 +168,7 @@ class GemtextTranslate_html {
protected $pageTitle = "";
public $translatedGemtext;
function __construct($parsedGemtext, $textDecoration=true) {
function __construct($parsedGemtext, $textDecorationEnabled=true) {
if (empty($parsedGemtext))
$parsedGemtext = "";
elseif (is_string($parsedGemtext))
@ -176,7 +177,7 @@ class GemtextTranslate_html {
// The text must be parsed
$parsedGemtext = gemtextParser($parsedGemtext);
$this->parsedGemtext = $parsedGemtext;
$this->translate($textDecoration);
$this->translate($textDecorationEnabled);
}
function addCss($css) {
@ -245,7 +246,7 @@ class GemtextTranslate_html {
}
public function translate($textDecoration=true) {
$output = "";
ob_start();
foreach ($this->parsedGemtext as $node) {
$mode = $node["mode"];
switch($mode) {
@ -253,27 +254,27 @@ class GemtextTranslate_html {
$text = $node["text"];
self::htmlPrepare($text);
if ($textDecoration) self::addTextDecoration($text);
$output .= "<p>$text</p>\n";
echo "<p>$text</p>\n";
break;
case "*":
$output .= "<ul>\n";
echo "<ul>\n";
foreach ($node["texts"] as $text) {
self::htmlPrepare($text);
if ($textDecoration) self::addTextDecoration($text);
$output .= "<li>$text\n";
print("<li>$text\n");
}
$output .= "</ul>\n";
echo "</ul>\n";
break;
case "```":
$text = implode("\n", $node["texts"]);
self::htmlPrepare($text);
$output .= "<pre>\n$text\n</pre>\n";
echo "<pre>\n$text\n</pre>\n";
break;
case ">":
$text = implode("\n", $node["texts"]);
self::htmlPrepare($text);
if ($textDecoration) self::addTextDecoration($text);
$output .= "<blockquote>\n$text\n</blockquote>\n";
echo "<blockquote>\n$text\n</blockquote>\n";
break;
case "=>":
$link = $node["link"];
@ -288,33 +289,34 @@ class GemtextTranslate_html {
preg_match("/^([^:]+):/", $link, $matches);
$protocol = @$matches[1];
if (empty($protocol)) $protocol = "local";
$output .= "<p><a class='$protocol' href='$link'>$linkText</a></p>\n";
echo "<p><a class='$protocol' href='$link'>$linkText</a></p>\n";
break;
case "#":
$title = $node["title"];
self::htmlPrepare($title);
if (empty($this->pageTitle)) $this->pageTitle = $title;
$output .= "<h1>$title</h1>\n";
echo "<h1>$title</h1>\n";
break;
case "##":
$title = $node["title"];
self::htmlPrepare($title);
$output .= "<h2>$title</h2>\n";
echo "<h2>$title</h2>\n";
break;
case "###":
$title = $node["title"];
self::htmlPrepare($title);
$output .= "<h3>$title</h3>\n";
echo "<h3>$title</h3>\n";
break;
case "^^^":
$textDecoration = !$textDecoration;
$this->textDecorationEnabled = !$this->textDecorationEnabled;
break;
default:
die("Unknown mode: '{$node["mode"]}'\n");
}
}
$this->translatedGemtext = $output;
$this->translatedGemtext = ob_get_contents();
ob_end_clean();
}
function getFullHtml() {
@ -322,7 +324,7 @@ class GemtextTranslate_html {
$css = array("/htmgem/css/htmgem.css");
else
$css = $this->cssList;
$output = <<<EOL
echo <<<EOL
<!DOCTYPE html>
<html>
<head>
@ -330,16 +332,14 @@ class GemtextTranslate_html {
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
EOL;
foreach ($css as $c) {
$output .= "<link type='text/css' rel='StyleSheet' href='$c'>\n";
echo "<link type='text/css' rel='StyleSheet' href='$c'>\n";
}
$output .= <<<EOL
echo <<<EOL
</head>
<body>\n
EOL;
$output .= $this->translatedGemtext;
$output .= "</body>\n</html>\n";
echo $output;
echo $this->translatedGemtext;
echo "</body>\n</html>\n";
}
public function __toString() {