//, see below⊠+ +## URL rewriting to set the style to use + +Modifying the web server configuration works but it's rather heavy. It's possible to test a particular style this way: +> https:/â/site.tld/htmgem/index.php?url=/url/page.gmi&style=<âŠ> + +It's also possible to make a URL rewriting which incorporate the style: +> rewrite ^(.+\.gmi)$ /htmgem/index.php?rw=1&url=$1; +> rewrite ^(.+\.gmi)\ *\|\ *([\w_]+)$ /htmgem/index.php?rw=1&url=$1&style=$2; + +For instance, when it's activated: +=> configuration-en.gmi%20|%20pre Shows the readable source code on the screen, using the markup ****. +=> configuration-en.gmi%20|%20source configuration-en.gmi | source : Downloads the source code. + +### With style already included⊠+ +=> configuration-en.gmi%20|%20htmgem Style //HtmGem//, the default style +=> configuration-en.gmi%20|%20none Style //none// +=> configuration-en.gmi%20|%20terminal Style //terminal// +=> configuration-en.gmi%20|%20black_wide Style //black wide// +=> configuration-en.gmi%20|%20simple Style //simple// +=> configuration-en.gmi%20|%20raw Style //raw// +=> configuration-en.gmi%20|%20debug Style //debug// + +=> ../css Style selector: the page containing the style allows to test them đ + +## Text decoration + +The text decoration, which interprets the **bold** for instance, is not part of GemText definition. The text decoration applies everywhere except on the titles and preformated texts. + +### Disable the text decoration + +It's possible to: +* disable and enable the text decoration with a line **^^^**, +* add what follows to the URL **rewriting**: +> &textDecoration=0 + +## BNF / Syntax + +HtmGem uses a precise implementation of the GemText BNF. It indicates exactly what text portions are to be used. +=> BNF-en.gmi BNF + +=> tutogemtext-en.gmi How to build GemText pages? + +ââââââââââââââââââââ ââââââââââââââââââââ + +Amongst the distributed files and directories, only the ones below are useful for HtmGem: +* **htmgem/*.php** : These files translate the GemText to HTML. +* **htmgem/css/htmgem.css** : If it's missing, the display will be without style â literally. +* **htmgem/css/âŠ** : Keep the styles you use. +The others can be deleted (included this present file //configuration-en.gmi//) although they are not harmful. diff --git a/docs/configuration-fr.gmi b/docs/configuration-fr.gmi new file mode 100644 index 0000000..52f4f91 --- /dev/null +++ b/docs/configuration-fr.gmi @@ -0,0 +1,63 @@ +# Configuration avancĂ©e +âïž Cette page fonctionne avec la rĂ©Ă©criture dâURL activĂ©e âïž + +Par dĂ©faut, le mĂȘme style est utilisĂ© pour toutes les pages, //htmgem/css/htmgem.css//, sauf lorsquâun fichier ayant le mĂȘme nom que la page mais avec lâextension **.css** existe dans le mĂȘme rĂ©pertoire. Dans ce cas, il est utilisĂ©. + +Lorsque lâoption css est activĂ© dans la configuration (voir //rewrite// plus bas) dâautres comportements sont possibles. **Attention**, cela ne fonctionnera pas avec un client Gemini puisque HtmGem nâest accessible que via un navigateur web. +* &style=**htmgem** : Utilise le style par dĂ©faut. +* &style=**none** : La page HTML est envoyĂ©e sans style. +* &style=**** : Le fichier htmgem/css/ .css est utilisĂ© en tant que style. +* &style=**/ ** : Le fichier indiquĂ© (chemin absolu) est utilisĂ© en tant que style. +* &style=**source** : Le code source de la page est envoyĂ©e au navigateur, voir ci-aprĂšs⊠+* &style=**pre** : Le code source de la page est envoyĂ©e au navigateur encadrĂ© par des // //, voir ci-aprĂšs⊠+ +## RĂ©Ă©criture dâURL pour prĂ©ciser le style Ă utiliser + +Modifier la configuration du serveur web fonctionne mais est assez lourd. On peut tester un style en particulier de la façon suivante : +> https:/â/site.tld/htmgem/index.php?url=/url/page.gmi&style=<âŠ> + +Il est aussi possible de faire une rĂ©Ă©criture dâURL qui intĂšgre le style : +> rewrite ^(.+\.gmi)$ /htmgem/index.php?rw=1&url=$1; +> rewrite ^(.+\.gmi)\ *\|\ *([\w_]+)$ /htmgem/index.php?rw=1&url=$1&style=$2; + +Par exemple, lorsque ce sera activĂ© : +=> configuration-fr.gmi%20|%20pre Produit le code source de façon lisble Ă lâĂ©cran en utilisant la balise ****. +=> configuration-fr.gmi%20|%20source configuration-fr.gmi | source : TĂ©lĂ©verse le code source. + +### Avec les styles dĂ©jĂ fournis⊠+ +=> configuration-fr.gmi%20|%20htmgem Style //HtmHem//, le style par dĂ©faut +=> configuration-fr.gmi%20|%20none Style //none// +=> configuration-fr.gmi%20|%20terminal Style //terminal// +=> configuration-fr.gmi%20|%20black_wide Style //black wide// +=> configuration-fr.gmi%20|%20simple Style //simple// +=> configuration-fr.gmi%20|%20raw Style //brut// +=> configuration-fr.gmi%20|%20debug Style //debug// + +=> ../css SĂ©lecteur de style : la page contenant les styles permet de les essayer đ + +## DĂ©coration du texte + +La dĂ©coration du texte, qui interprĂȘte le **gras** par exemple, ne fait pas partie de la dĂ©finition de GemText. La dĂ©coration du texte sâapplique partout sauf sur les titres et blocs prĂ©formatĂ©s. + +### DĂ©sactiver la dĂ©coration du texte + +On peut : +* dĂ©sactiver et activer la dĂ©coration du texte avec une ligne **^^^**, +* ajouter ce qui suit Ă la **rĂ©Ă©criture** dâURL : +> &textDecoration=0 + +## BNF / Syntax + +HtmGem utilise une implĂ©mentation prĂ©cise de la BNF de GemText. Il indique exactement quelle portions de texte doivent ĂȘtre utilisĂ©es. +=> BNF-fr.gmi BNF + +=> tutogemtext-fr.gmi Comment faire des pages GemText ? + +ââââââââââââââââââââ ââââââââââââââââââââ + +Parmi les fichiers et rĂ©pertoires distribuĂ©s, seuls sont utiles pour le fonctionnement de HtmGem : +* **htmgem/*.php** : Ces fichiers se chargent de traduire le GemText en HTML. +* **htmgem/css/htmgem.css** : Sâil manque, lâaffichage sera dĂ©pourvu de style â littĂ©ralement. +* **htmgem/css/âŠ** : Conservez les styles que vous utilisez. +Les autres peuvent ĂȘtre supprimĂ©s (y compris ce prĂ©sent fichier //configuration-fr.gmi//) bien quâils ne prĂ©sentent aucun danger. diff --git a/docs/index.gmi b/docs/index.gmi new file mode 100644 index 0000000..bc2aaa3 --- /dev/null +++ b/docs/index.gmi @@ -0,0 +1,9 @@ +# Developers' documentation + +=> BNF-en.gmi BNF / Backus-Naur Form + +=> https://gmi.sbgodin.fr/htmgem Project main page +=> https://tildegit.org/Sbgodin/htmgem Source code, comments +=> https://gemini.circumlunar.space Main Gemini capsule +=> ../CHANGELOG.gmi Change log +=> ../COPYING.gmi Licence Gnu Affero General Public License v3 â 19 november 2007 diff --git a/docs/installation-en.gmi b/docs/installation-en.gmi new file mode 100644 index 0000000..b3a03de --- /dev/null +++ b/docs/installation-en.gmi @@ -0,0 +1,42 @@ +# HtmGem, installation + +To run HtmGem â after having copied the files â there is nothing to do but to add the URL rewriting rules. + +## Prerequisites + +* Php v7.3 minimum +* Module **php-mbstring** to manage unicode +* A web server (Apache and Nginx tested) +* Module **mod-rewrite** to handle the Gemini pages + +## Installation + +### Download +=> https://tildegit.org/sbgodin/HtmGem/archive/master.zip Stable version +=> https://tildegit.org/Sbgodin/htmgem Project repository + +### Nginx +``` +# This text must be placed in the server's configuration +index index.gmi index.php index.html +rewrite ^(.+\.gmi)$ htmgem/index.php?rw=1&url=$1; +``` + +### Apache +``` +# This text can be placed at the root of the web site in a file ".htaccess". +DirectoryIndex index.gmi index.php index.html +RewriteEngine on +RewriteRule ^(.+\.gmi)$ htmgem/index.php?rw=1&url=$1 +``` + +Afterwards, +* When a file ends by **.gmi.** is asked, HtmGem will display it in the browser. +* When only the directory is asked (http:/â/site.tld/path) the file //index.gmi// will be automatically choosen. + +=> tutogemtext-en.gmi How to build GemText pages? + +## Advanced configuration + +Add additional styles as a link parameter or adapt the text decoration: +=> configuration-en.gmi Advanced configuration diff --git a/docs/installation-fr.gmi b/docs/installation-fr.gmi new file mode 100644 index 0000000..798efb7 --- /dev/null +++ b/docs/installation-fr.gmi @@ -0,0 +1,42 @@ +# HtmGem, installation + +Pour faire fonctionner HtmGem â aprĂšs avoir copiĂ© les fichiers â il ne reste quâĂ ajouter les rĂšgles de rĂ©Ă©criture dâURL (//URL Rewriting//). + +## PrĂ©requis + +* Php v7.3 minimum +* Module **Php-mbstring** pour gĂ©rer lâunicode +* Un serveur web (Apache et Nginx testĂ©s) +* Module **mod-rewrite** pour prendre en charge les pages Gemini + +## Installation + +### TĂ©lĂ©chargement +=> https://tildegit.org/sbgodin/HtmGem/archive/master.zip Version stable +=> https://tildegit.org/Sbgodin/htmgem DĂ©pĂŽt du projet + +### Nginx +``` +# Ce texte doit ĂȘtre placĂ© dans la configuration du serveur. +index index.gmi index.php index.html +rewrite ^(.+\.gmi)$ htmgem/index.php?rw=1&url=$1; +``` + +### Apache +``` +# Ce texte peut se placer Ă la racine du site dans un fichier ".htaccess". +DirectoryIndex index.gmi index.php index.html +RewriteEngine on +RewriteRule ^(.+\.gmi)$ htmgem/index.php?rw=1&url=$1 +``` + +Par la suite, +* Quand un fichier se terminant par **.gmi** sera demandĂ©, HtmGem lâaffichera dans le navigateur. +* Quand seul le rĂ©pertoire sera demandĂ© (http:/â/site.tld/path) le fichier //index.gmi// sera automatiquement choisi. + +=> tutogemtext-fr.gmi Comment faire des pages GemText ? + +## Configuration avancĂ©e + +Ajoutez des styles supplĂ©mentaires en paramĂštre de lien ou adaptez la dĂ©coration du texte : +=> configuration-fr.gmi Configuration avancĂ©e diff --git a/docs/tutogemtext-en.gmi b/docs/tutogemtext-en.gmi new file mode 100644 index 0000000..163f169 --- /dev/null +++ b/docs/tutogemtext-en.gmi @@ -0,0 +1,74 @@ +# GemText tutorial + +Gemini is a protocol, a syntax, servers and clients. Its syntax is the GemText. Its principle is that it's the Gemini browser of the user which decides about the display. The font, the size, the page background, everything. One of the goal is to focus on the text and some other details explained below. + +The paragraph you just read is on one physical line, cut by the program you use in several logical lines to fit your screen. Between this text line and the preceding one, there's an empty line to mark the paragraph change. +Here, I just did a line wrap. The margin should be lower, but it depends upon the program you are using. + +The titles of level one, two and three are first written as they are physically on this page, then on the line after they are displayed normally by the Gemini browser: + +â# Title level 1 +# Title level 1 + +â## Title level 2 +## Title level 2 + +â### Title level 3 +### Title level 3 + +# Citations + +â> Text citation. The line can be as long as needed, it's your program that must cut the line to display it. One physical line can be long, but there's no need to wrap the line. +> Text citation. The line can be as long as needed, it's your program that must cut the line to display it. One physical line can be long, but there's no need to wrap the line. + +# Preformated blocks + +â``` +The preformated blocks are lines enclosed by ``` on one line before the block and a ``` after the block. +â``` +``` +The preformated blocks are lines enclosed by ``` on one line before the block and a ``` after the block. +``` + +# Unordered lists + +â* The unordered lists are lines beginning by * one after the others. +â* They can be used to enumerate. +â* However, GemText doesn't recognize the ordered lists. +* The unordered lists are lines beginning by * one after the others. +* They can be used to enumerate. +* However, GemText doesn't recognize the ordered lists. + +# The links + +There can be only one link on a line. And the line is dedicated to! Here's for instance a link to the site centralizing at the moment the information about Gemini: + +â=> gemini:/â/gemini.circumlunar.space/docs/specification.gmi Gemini specifications +=> gemini://gemini.circumlunar.space/docs/specification.gmi Gemini specifications + +â=> https:/â/gemini.circumlunar.space/docs/specification.gmi +=> https://gemini.circumlunar.space/docs/specification.gmi + +# Text decoration + +The text decoration is not part of Gemini's specifications. + +This *â*line*â* uses the /â/text decoration/â/ which can ~â~strike through~â~ or _â_underline_â_ words. +This **line** uses the //text decoration// which can ~~strike through~~ or __underline__ words. + +It's possible to disable and enable the text decoration with **^^^** on a line. + +And voilĂ ! You know everything đ„ł + +ââââââââââââââââââââ ââââââââââââââââââââ + +## HtmGem + +HtmGem allows to host Gemini pages and publish them on a web server with **Php**. When opening a page ***.gmi**, it translates it for the web browser. This page is displayed this way. It allows to use the Gemini syntax (GemText) on the web. +=> https://gmi.sbgodin.fr/htmgem + + +### License of this page +This page is under the free licence **CC BY-SA 2.0**. +=> https://creativecommons.org/licenses/by-sa/2.0/en/ Text under license CC BY-SA 2.0 +=> gemini://gmi.sbgodin.fr/ gemini:/â/gmi.sbgodin.fr/ âž» Christophe HENRY diff --git a/tutogemtext.gmi b/docs/tutogemtext-fr.gmi similarity index 84% rename from tutogemtext.gmi rename to docs/tutogemtext-fr.gmi index 32f03c7..dd1c3e0 100644 --- a/tutogemtext.gmi +++ b/docs/tutogemtext-fr.gmi @@ -1,4 +1,4 @@ -# Tutorial GemText +# Tutoriel GemText Gemini est un protocole, une syntaxe, des serveurs et des clients. Sa syntaxe est le GemText. Son principe est que câest le navigateur Gemeni de lâutilisateur qui dĂ©cide de lâaffichage. La police de caractĂšre, la taille, le fond dâĂ©cran, tout. Lâun des buts recherchĂ©s est de se concentrer sur le texte et quelques autres dĂ©tails abordĂ©s ci-aprĂšs. @@ -24,10 +24,10 @@ Les titres de niveau un, deux puis trois sont dâabord Ă©crits ci-aprĂšs tel qu # Blocs prĂ©formatĂ©s â``` -Les blocs prĂ©formatĂ©s sont des lignes encadrĂ©es par un ``` sur une ligne avant le bloc et un ``` aprĂšs le bloc. Les lignes contenant ``` ne sont pas affichĂ©es : +Les blocs prĂ©formatĂ©s sont des lignes encadrĂ©es par un ``` sur une ligne avant le bloc et un ``` aprĂšs le bloc. â``` ``` -Les blocs prĂ©formatĂ©s sont des lignes encadrĂ©es par un ``` sur une ligne avant le bloc et un ``` aprĂšs le bloc. Les lignes contenant ``` ne sont pas affichĂ©es : +Les blocs prĂ©formatĂ©s sont des lignes encadrĂ©es par un ``` sur une ligne avant le bloc et un ``` aprĂšs le bloc. ``` # Listes non-ordonnĂ©es @@ -44,7 +44,7 @@ Les blocs prĂ©formatĂ©s sont des lignes encadrĂ©es par un ``` sur une ligne avan Il ne peut exister quâun lien par ligne. Et la ligne est dĂ©diĂ©e à ça ! Voici par exemple un lien vers le site centralisant pour le moment les informations sur Gemini : â=> gemini:/â/gemini.circumlunar.space/docs/specification.gmi SpĂ©cifications de Gemini -=> gemini:/â/gemini.circumlunar.space/docs/specification.gmi SpĂ©cifications de Gemini +=> gemini://gemini.circumlunar.space/docs/specification.gmi SpĂ©cifications de Gemini â=> https:/â/gemini.circumlunar.space/docs/specification.gmi => https://gemini.circumlunar.space/docs/specification.gmi @@ -58,8 +58,7 @@ Cette **ligne** utilise la //dĂ©coration du texte// qui peut ~~barrer~~ ou __sou On peut dĂ©sactiver et activer la dĂ©coration du texte avec **^^^** sur une ligne. -Et voilĂ ! Vous savez tout ce qui est Ă savoir đ„ł Les spĂ©cifications complĂštes sont sur le site de Gemini : -=> https://gemini.circumlunar.space/docs/specification.gmi +Et voilĂ ! Vous savez tout đ„ł ââââââââââââââââââââ ââââââââââââââââââââ @@ -70,9 +69,6 @@ HtmGem permet dâhĂ©berger des pages Gemini et de les publier sur un serveur we ### License de cette page -Cette page est sous licence libre **CC BY-SA 2.0 FR**. -=> https://creativecommons.org/licenses/by-sa/2.0/fr/ Texte de la licence CC BY-SA 2.0 FR +Cette page est sous licence libre **CC BY-SA 2.0**. +=> https://creativecommons.org/licenses/by-sa/2.0/fr/ Texte sous licence CC BY-SA 2.0 => gemini://gmi.sbgodin.fr/ gemini:/â/gmi.sbgodin.fr/ âž» Christophe HENRY - -### Navigation -=> index.gmi diff --git a/index.gmi b/index.gmi index f140353..070df28 100644 --- a/index.gmi +++ b/index.gmi @@ -1,133 +1,13 @@ -# HtmGem, voir Gemini via le web +# HtmGem -Ceci est la page dâinstallation et de prĂ©sentation dâ**HtmGem**. -=> tutogemtext.gmi Cliquez ici pour voir le tutoriel pour Ă©crire des pages Gemini. +=> docs/installation-fr.gmi Installation de HtmGem, en français +HtmGem rend vos pages **Gemini** accessibles sur le web. Il fonctionne aussi en hĂ©bergement mutualisĂ©. +=> docs/tutogemtext-fr.gmi Tutoriel GemText -HtmGem permet dâhĂ©berger des pages Gemini et de les publier sur un serveur web muni de **Php**. Ă lâouverture dâune page ***.gmi**, il la traduit pour le navigateur web. Cette prĂ©sente page est affichĂ©e de cette façon. Gemini utilise son propre protocole, format, clients et serveurs ; HtmGem permet dâen utiliser le format (Gemtext) via le web. +=> docs/installation-en.gmi HtmGem installation, in English +HtmGem makes your **Gemini** pages reachable on the web. It can be used on a shared host. +=> docs/tutogemtext-en.gmi GemText tutorial -``` -Gemini est un nouveau protocole internet qui : -* est plus lourd que gopher, -* est plus lĂ©ger que le web, -* nâen remplacera aucun, -* vise le rapport puissance sur poids maximum, -* prend la vie privĂ©e trĂšs sĂ©rieusement. -``` -=> https://gemini.circumlunar.space/ -=> https://tildegit.org/sbgodin/HtmGem/archive/master.zip TĂ©lĂ©chargez la branche courante pour lâinstaller -=> https://tildegit.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 - -=> CHANGELOG.gmi Journal des modifications (//changelog//) -=> COPYING.gmi GNU Affero General Public License (AGPLv3) - -ââââââââââââââââââââ ââââââââââââââââââââ - -# Installation - -Pour faire fonctionner HtmGem â aprĂšs avoir copiĂ© les fichiers â il ne reste quâĂ ajouter une rĂšgle de rĂ©-Ă©criture dâURL (//URL Rewriting//). Si vous pouvez lire ce texte en ayant demandĂ© //htmgem.php// avec le navigateur, il ne reste que cette derniĂšre Ă©tape Ă franchir đ - -## PrĂ©requis - -* Php v7.3 minimum -* Module **Php-mbstring** pour gĂ©rer lâunicode -* Un serveur web (Apache et Nginx testĂ©s) -* Module **mod-rewrite** pour intercepter les pages Gemini - -### Nginx -``` -# Ce texte doit ĂȘtre placĂ© dans la configuration du serveur. -index index.php index.gmi index.html -rewrite ^(.+\.gmi)$ htmgem/?url=$1; -``` - -### Apache -``` -# Ce texte peut se placer Ă la racine du site dans un fichier ".htaccess". -DirectoryIndex index.php index.gmi index.html -RewriteEngine on -RewriteRule ^(.+\.gmi)$ htmgem/?url=$1 -``` - -Par la suite, -* Quand un fichier se terminant par **.gmi** sera demandĂ©, HtmGem le traduira Ă la volĂ©e en HTML. -* Quand seul le rĂ©pertoire sera demandĂ© (http:/â/site.tld/path) le fichier //index.gmi// sera automatiquement choisi. - -Le paramĂ©trage dâApache et de Nginx est similaire. Par la suite, la syntaxe Nginx sera utilisĂ©e. - -## Tester HtmGem - -Il est supposĂ© que HtmGem est installĂ© Ă la racine du site dans un rĂ©pertoire //HtmGem//. Sinon, il faudra simplement adapter les liens. - -Chargez cette prĂ©sente page directement, en cliquant ci-aprĂšs. -=> index.gmi - -Enfin, pour vĂ©rifier que le fichier //index.gmi// est automatiquement appelĂ© quand le fichier **.gmi** nâest pas indiquĂ© : -=> /htmgem - -Lâinstallation est terminĂ©e đ„ł La suite du texte donne des informations complĂ©mentaires, et nâest pas nĂ©cessaire dans lâimmĂ©diat. Les fichiers **.gmi** que vous crĂ©erez seront disponibles dĂšs maintenant. -=> tutogemtext.gmi Inspirez-vous du tutoriel - -ââââââââââââââââââââ ââââââââââââââââââââ - -# Configuration avancĂ©e - -Par dĂ©faut, le style est incorporĂ© dans chaque page rĂ©cupĂ©rĂ©e par le navigateur web. Le mĂȘme style est utilisĂ© pour toutes les pages, //htmgem/css/htmgem.css//, sauf lorsquâun fichier ayant le mĂȘme nom que la page mais avec lâextension **.css** existe dans le mĂȘme rĂ©pertoire. Dans ce cas, il est utilisĂ©. - -Lorsque lâoption css est activĂ© dans la configuration (voir //rewrite// plus haut) dâautres comportements sont possibles. **Attention**, cela ne fonctionnera pas avec un client Gemini puisque HtmGem nâest accessible que via un navigateur web. -* &style=**htmgem** : Utilise le style par dĂ©faut, mais en tant que fichier externe. -* &style=**none** : La page HTML est envoyĂ©e sans style. -* &style=**** : Le fichier htmgem/css/ .css est utilisĂ© en tant que style externe. -* &style=**/ ** : Le fichier indiquĂ© (chemin absolu) est utilisĂ© en tant que style externe. -* &style=**source** : Le code source de la page est envoyĂ©e au navigateur, voir ci-aprĂšs⊠-* &style=**pre** : Le code source de la page est envoyĂ©e au navigateur encadrĂ© par des // //, voir ci-aprĂšs⊠- -## RĂ©Ă©criture dâURL pour prĂ©ciser le style Ă utiliser - -Modifier la configuration du serveur web fonctionne mais est assez lourd. On peut tester un style en particulier de la façon suivante : -> https:/â/site.tld/htmgem/index.php?url=/url/page.gmi&style=<âŠ> - -Il est aussi possible de faire une rĂ©Ă©criture dâURL qui intĂšgre le style : -> rewrite ^(.+\.gmi)$ /htmgem/?url=$1; -> rewrite ^(.+\.gmi)\ *\|\ *([\w_]+)$ /htmgem/?url=$1&style=$2; - -Par exemple, lorsque ce sera activĂ© : -=> index.gmi%20|%20source Le lien index.gmi | source Produit le code source, pas bien lisible Ă lâĂ©cran. Ă utiliser avec //wget//. -=> index.gmi%20|%20pre Produit le code source de façon lisble Ă lâĂ©cran en utilisant la balise ****. - -=> index.gmi Ouvre la page avec le style par dĂ©faut, avec le style importĂ© dans lâen-tĂȘte. - -=> css SĂ©lecteur de style : une page de dĂ©mo pour essayer chaque style đ - -### Avec les styles dĂ©jĂ fournis - -=> index.gmi%20|%20htmgem Ouvre la page avec le style par dĂ©faut (//htmgem.css//), mais le style est importĂ© dans lâen-tĂȘte. -=> index.gmi%20|%20none Ouvre la page courante avec le style //none//. Aucune CSS utilisĂ©e. - -=> index.gmi%20|%20terminal Style //terminal// -=> index.gmi%20|%20black_wide Style //black wide// -=> index.gmi%20|%20simple Style //simple// - -## DĂ©coration du texte - -La dĂ©coration du texte, qui interprĂȘte le **gras** par exemple, ne fait pas partie de la dĂ©finition de GemText. La dĂ©coration du texte sâapplique partout sauf sur les titres et blocs prĂ©formatĂ©s. - -### DĂ©sactiver la dĂ©coration du texte - -On peut : -* dĂ©sactiver et activer la dĂ©coration du texte avec une ligne **^^^**, -* ajouter ce qui suit Ă la **rĂ©Ă©criture** dâURL : -> &textDecoration=0 - -ââââââââââââââââââââ ââââââââââââââââââââ - -# Quand tout marche⊠- -Parmi les fichiers et rĂ©pertoires distribuĂ©s, seuls sont utiles pour le fonctionnement de HtmGem : -* **htmgem/index.php** : Il se charge de traduire le gemtext en HTML. -* **htmgem/css/htmgem.css** : Sâil manque, lâaffichage sera dĂ©pourvu de style â littĂ©ralement. -* **htmgem/css/⊠: Conservez les styles que vous utilisez. -Les autres peuvent ĂȘtre supprimĂ©s (y compris ce prĂ©sent fichier //index.gmi//) bien quâils ne prĂ©sentent aucun danger. +=> docs/index.gmi **Developers' documentation** +The documentation (in English) for the developers's stands here. Please read them carefully before doing anything on the source code. diff --git a/index.html b/index.html new file mode 100644 index 0000000..23fed8c --- /dev/null +++ b/index.html @@ -0,0 +1,19 @@ + + + +HtmGem + + + + +HtmGem
++
Php required
+ ++
+
+
Help
+ + + diff --git a/index.php b/index.php index b286ba5..5c2d685 100644 --- a/index.php +++ b/index.php @@ -4,11 +4,12 @@ require_once "lib-htmgem.php"; # The url argument is always absolute compared to the document root. $url = @$_REQUEST["url"]; +$urlRewriting = @$_REQUEST["rw"]=="1"; /* Installation page * * Accessing directly /htmgem will make display the self-hosted documentation - * contained in "index.gmi". If it's removed, diplay an empty page with a + * contained in "index.gmi". If it's removed, display an empty page with a * comment */ if (empty($url)) { @@ -16,20 +17,25 @@ if (empty($url)) { http_response_code(403); die(""); } - $t = new \htmgem\GemTextTranslate_html(@file_get_contents("index.gmi")); + $t = new \htmgem\GemTextTranslate_html(@file_get_contents("index.gmi"), true, "/htmgem"); echo $t->getFullHtml(); exit(); } $documentRoot = $_SERVER['DOCUMENT_ROOT']; +if (!preg_match("/\.gmi$/", $url)) { + if ($url[-1] == "/") + $url = $url."index.gmi"; + else + $url = $url."/index.gmi"; +} + # Removes the headling and trailling slashes, to be sure there's not any. $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 $go404 = true; // Says 404 even if the file exists to not give any information. @@ -96,7 +102,11 @@ EOL; exit(); } -$t = new \htmgem\GemTextTranslate_html($fileContents, $textDecoration); +if ($urlRewriting) + $baseUrl = null; +else + $baseUrl = dirname($url); +$t = new \htmgem\GemTextTranslate_html($fileContents, $textDecoration, $baseUrl); if ("none" == $style) { $t->addCss(""); } elseif ("/" == @$style[0]) { diff --git a/lib-htmgem.php b/lib-htmgem.php index 558dbb1..104bf5b 100644 --- a/lib-htmgem.php +++ b/lib-htmgem.php @@ -10,6 +10,8 @@ mb_regex_encoding("UTF-8"); * @param str $fileContents the gemtext to parse */ function gemtextParser($fileContents) { + if (empty($fileContents)) return array(); + $fileContents = rtrim($fileContents); // removes last empty line $fileLines = explode("\n", $fileContents); $mode = null; $current = array(); @@ -30,11 +32,11 @@ function gemtextParser($fileContents) { if ('^^^' == $line3) { yield array("mode" => "^^^"); } elseif ("#" == $line1) { - preg_match("/^(#{1,3})\s*(.+)/", $line, $matches); - yield array("mode" => $matches[1], "title" => trim($matches[2])); + preg_match("/^(#{1,3})\s*(.+)?/", $line, $matches); + yield array("mode" => $matches[1], "title" => trim(@$matches[2])); } elseif ("=>" == $line2) { preg_match("/^=>\s*([^\s]+)(?:\s+(.*))?$/", $line, $matches); - yield array("mode" => "=>", "link" => trim($matches[1]), "text" => trim(@$matches[2])); + yield array("mode" => "=>", "link" => trim(@$matches[1]), "text" => trim(@$matches[2])); } elseif ("```" == $line3) { preg_match("/^```\s*(.*)$/", $line, $matches); $current = array("mode" => "```", "alt" => trim($matches[1]), "texts" => array()); @@ -49,7 +51,7 @@ function gemtextParser($fileContents) { $mode = "*"; } else { // text_line - yield array("mode"=>"", "text" => trim($line)); + yield array("mode"=>"", "text" => rtrim($line)); } } else { if ("```"==$mode) { @@ -58,7 +60,7 @@ function gemtextParser($fileContents) { $current = array(); $mode = null; } else { - $current["texts"] []= $line; // No trim() as itâs a preformated text! + $current["texts"] []= rtrim($line); // No ltrim() as itâs a preformated text! } } elseif (">"==$mode) { if (">" == $line1) { @@ -102,55 +104,67 @@ function gemtextParser($fileContents) { class GemtextTranslate_gemtext { function __construct($parsedGemtext) { - $this->parsedGemtext = $parsedGemtext; + if (empty($parsedGemtext)) $parsedGemtext = ""; + // to delete the last empty lines + $parsedGemtext = rtrim($parsedGemtext); + // The text must be parsed + $this->parsedGemtext = gemtextParser($parsedGemtext); $this->translate(); } protected function translate() { - ob_start(); + $output = ""; foreach ($this->parsedGemtext as $node) { $mode = $node["mode"]; switch($mode) { case "": - echo $node["text"]."\n"; + $output .= $node["text"]."\n"; break; case "*": foreach ($node["texts"] as $text) { - echo "* $text\n"; + $output .= "* $text\n"; } break; case "```": - print("```\n"); + $alt = $node["alt"]; + if (empty($alt)) + $output .= "```\n"; + else + $output .= "``` $alt\n"; foreach ($node["texts"] as $text) { - echo "$text\n"; + $output .= "$text\n"; } - print("```\n"); + $output .= "```\n"; break; case ">": foreach ($node["texts"] as $text) { - echo "> $text\n"; + if (empty($text)) + $output .= ">\n"; + else + $output .= "> $text\n"; } break; case "=>": $linkText = $node["text"]; + $link = $node["link"]; if (!empty($linkText)) $linkText = " $linkText"; - print("=> ".$node["link"].$linkText."\n"); + if (!empty($link)) $link = " $link"; + $output .= "=>".$link.$linkText."\n"; break; case "#": case "##": case "###": - print("$mode ".$node["title"]."\n"); + $output .= "$mode ".$node["title"]."\n"; break; case "^^^": - print("^^^\n"); + $output .= "^^^\n"; break; default: die("Unknown mode: '{$node["mode"]}'\n"); } } - $this->translatedGemtext = ob_get_contents(); - ob_end_clean(); + $this->translatedGemtext = $output; } public function __toString() { @@ -168,14 +182,13 @@ class GemtextTranslate_html { protected $pageTitle = ""; public $translatedGemtext; - function __construct($parsedGemtext, $textDecoration=true) { - if (empty($parsedGemtext)) - $parsedGemtext = ""; - elseif (is_string($parsedGemtext)) - // to delete the last empty line,in HTML - $parsedGemtext = rtrim($parsedGemtext); - // The text must be parsed - $parsedGemtext = gemtextParser($parsedGemtext); + function __construct($parsedGemtext, $textDecoration=true, $baseUrl=Null) { + $this->baseUrl = $baseUrl; + if (empty($parsedGemtext)) $parsedGemtext = ""; + // to delete the last empty lines + $parsedGemtext = rtrim($parsedGemtext); + // The text must be parsed + $parsedGemtext = gemtextParser($parsedGemtext); $this->parsedGemtext = $parsedGemtext; $this->translate($textDecoration); } @@ -245,46 +258,74 @@ class GemtextTranslate_html { } } + protected static function spacesCompress(&$text) { + # Replaces several spaces (0x20) by only one + $text = preg_replace("/ +/", " ", $text); + } + + protected static function resolve_path($path) { + $absolute = "/"==$path[0]; + $parts = array_filter(explode("/", $path), 'strlen'); + $chuncks = array(); + foreach ($parts as $part) { + if ('.' == $part) continue; + if ('..' == $part) { + array_pop($chuncks); + } else { + $chuncks[] = $part; + } + } + $output = implode("/", $chuncks); + if ($absolute) $output = "/".$output; + return $output; + } + public function translate($textDecoration=true) { - ob_start(); + $output = ""; foreach ($this->parsedGemtext as $node) { $mode = $node["mode"]; switch($mode) { case "": $text = $node["text"]; + self::spacesCompress($text); self::htmlPrepare($text); if ($textDecoration) self::addTextDecoration($text); - echo "
$text
\n"; + $output .= "$text
\n"; break; case "*": - echo "\n"; + $output .= "
\n"; break; case "```": $text = implode("\n", $node["texts"]); self::htmlPrepare($text); - echo "\n"; foreach ($node["texts"] as $text) { + self::spacesCompress($text); self::htmlPrepare($text); if ($textDecoration) self::addTextDecoration($text); - print("
\n"; + $output .= "- $text\n"); + $output .= "
- $text\n"; } - echo "
\n$text\n\n"; + $output .= "\n$text\n\n"; break; case ">": - foreach ($node["texts"] as &$text) { + $output .= "\n"; + foreach ($node["texts"] as $text) { + self::spacesCompress($text); self::htmlPrepare($text); if ($textDecoration) self::addTextDecoration($text); + $output .= "\n"; break; case "=>": $link = $node["link"]; $linkText = $node["text"]; if (empty($linkText)) { $linkText = $link; + self::spacesCompress($linkText); self::htmlPrepare($linkText); } else { + self::spacesCompress($linkText); // Don't double encode, just escapes quotes, "<" and ">". // So "I'm>" becomes "I'>". The & remains untouched. $link = htmlspecialchars($link, ENT_HTML5|ENT_QUOTES, "UTF-8", false); @@ -293,24 +334,34 @@ class GemtextTranslate_html { } preg_match("/^([^:]+):/", $link, $matches); $protocol = @$matches[1]; - if (empty($protocol)) $protocol = "local"; - echo "\n"; + if (empty($protocol)) { + $protocol = "local"; + 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"; + } + } + $output .= "\n"; break; case "#": $title = $node["title"]; + self::spacesCompress($linkText); self::htmlPrepare($title); if (empty($this->pageTitle)) $this->pageTitle = $title; - echo "$text
\n"; } - $text = implode("
\n", $node["texts"]); - echo "\n$text\n\n"; + $output .= "$title
\n"; + $output .= "$title
\n"; break; case "##": $title = $node["title"]; + self::spacesCompress($linkText); self::htmlPrepare($title); - echo "$title
\n"; + $output .= "$title
\n"; break; case "###": $title = $node["title"]; + self::spacesCompress($linkText); self::htmlPrepare($title); - echo "$title
\n"; + $output .= "$title
\n"; break; case "^^^": $textDecoration = !$textDecoration; @@ -320,8 +371,7 @@ class GemtextTranslate_html { } } - $this->translatedGemtext = ob_get_contents(); - ob_end_clean(); + $this->translatedGemtext = $output; } function getFullHtml() { @@ -329,7 +379,7 @@ class GemtextTranslate_html { $css = array("/htmgem/css/htmgem.css"); else $css = $this->cssList; - echo <<@@ -337,14 +387,16 @@ class GemtextTranslate_html { EOL; foreach ($css as $c) { - echo "\n"; + $output .= "\n\n"; } - echo << \n EOL; - echo $this->translatedGemtext; - echo "\n\n"; + $output .= $this->translatedGemtext; + $output .= "\n