Compare commits

..

4 Commits

Author SHA1 Message Date
pisoj 34838936dd Update README.md 2026-05-30 16:30:22 +02:00
pisoj 9769b64610 Merge pull request '[fix] Disable separate selector characters for PDF and XML' (#1) from small-fixes into master 2026-05-24 23:59:17 +02:00
pisoj aecd851d65 Add a note about server behaviour expectations 2026-05-22 11:18:54 +02:00
pisoj e0bb258de0 [fix] Disable separate selector characters for PDF and XML
Lagrange does not recocnise 'P' and 'X' types as links.
2026-05-22 11:04:00 +02:00
2 changed files with 38 additions and 41 deletions
+38 -35
View File
@@ -1,7 +1,21 @@
> **Note**
>
> This program expects that your Gopher server treats **empty lines** as **information lines**.
>
> It also expects the server to **add the hostname** and the **port** number at the end of links.
### Compiling
This program compiles like any other ordinary Go project, simply **run** `go build .` in the project directory.
You need to have Go toolchain installed:
```shell
# Debian
sudo apt install golang
# Fedora
sudo dnf install golang
```
Then, just **clone the repo** and run **`go build .`** to compile an executable.
### Usage
```shell
@@ -10,68 +24,57 @@ gemtext2gophermap input.gmi output_gophermap [max line length (default 70)] [pre
## Example
### Input Gemtext
_input.gmi_
````gemtext
Everything until the first <!--break--> in the map file will be put in place of the insert-gopher tag.
**input.gmi**
````markdown
Everything until the first <!--break--> in the map file will be put in place of the following insert-gopher tag.
```html
<!--insert-gopher-->
```
The following <script> tag will be removed because it is between to web-only tags.
The <script> tag should be removed because it is between two web-only tags.
```html
<!--web-only-->
```
```html
<script>
console.log("joj")
</script>
```
```html
<!--web-only-->
```
> Here, the contents after the first break in the map file will be put
> Everything after the first <!--break--> in the map file:
```html
<!--insert-gopher-->
```
````
### A map file
_map.txt_
**map.txt**
```gophermap
<?php
echo "i" . date(DATE_RFC2822) . "\t/FAKE\tNULL\t0";
echo "i" . date(DATE_RFC2822) . "\tFAKE\tNULL\t0";
?>
<!--break-->
iIf your Gopher server supports running PHP it should have printed the current date. /FAKE NULL 0
A line from map.txt
```
### Command
> If a line in map.txt isn't in format `i /PATH host 123` it **will not** automatically get converted into that format,
> your **server is expected to do that** or you should write that explicitly in the map.txt file.
>
> This has been done to allow injecting PHP scripts.
> (to avoid: `i<?php /FAKE NULL 0`)
#### Command
```shell
gemtext2gophermap input.gmi - 70 map.txt
```
If `-` is passed instead of `input/output` file name `stdin/stdout` will be used. Reading the **map file from stdin** is **not supported**.
If `-` is passed instead of `input or output` file name `stdin or stdout` will be used. Reading the **map file from stdin** is **not supported**.
### Output
#### Output
```gophermap
iEverything until the first <!--break--> in the map file will be put in /FAKE NULL 0
iplace of the insert-gopher tag. /FAKE NULL 0
iplace of the following insert-gopher tag. /FAKE NULL 0
<?php
echo "i" . date(DATE_RFC2822) . "\t/FAKE\tNULL\t0";
echo date(DATE_RFC2822);
?>
iThe following <script> tag will be removed because it is between to /FAKE NULL 0
iweb-only tags. /FAKE NULL 0
iThe <script> tag should be removed because it is between two web-only /FAKE NULL 0
itags. /FAKE NULL 0
i> Everything after the first <!--break--> in the map file: /FAKE NULL 0
i> Here, the contents after the first break in the map file will be put /FAKE NULL 0
iIf your Gopher server supports running PHP it should have printed the current date. /FAKE NULL 0
A line from map.txt
```
-6
View File
@@ -90,14 +90,8 @@ func (params *GopherTypeCharParams) GopherTypeChar(path string, isDir bool) stri
return "I"
case strings.HasPrefix(mimeType, "audio/"):
return "s"
case mimeType == "application/pdf":
return "P"
case strings.HasPrefix(mimeType, "text/html"):
return "h"
case strings.HasPrefix(mimeType, "text/rtf"):
return "r"
case strings.HasPrefix(mimeType, "text/xml") || strings.HasPrefix(mimeType, "application/xml"):
return "X"
default:
return "9"
}