Improved gmi2map logic

This commit is contained in:
Luxferre
2023-04-03 21:37:12 +03:00
parent aa3a252203
commit 8060459dc7
2 changed files with 13 additions and 10 deletions
+9 -9
View File
@@ -73,7 +73,7 @@ Note that by default, reflow logic in `gmi2map.sh` is optional and you have to s
cat [file] | gmi2map.sh [page_width] [leading_spaces] [trailing_spaces] [placeholder_char] cat [file] | gmi2map.sh [page_width] [leading_spaces] [trailing_spaces] [placeholder_char]
``` ```
I.e. it looks like the `phlow.sh` and `gopherinfo.sh` options combined, but the spaces part only applies to the reflow, which is also off by default. I.e. it looks like the `phlow.sh` and `gopherinfo.sh` options combined, but the spaces part only applies to the reflow, which is also off by default. Also, it doesn't align the whitespaces after the infolines unless there is non-zero amount of trailing spaces.
Example - imagine we have this rudimentary Gemtext document in the `example.gmi` file: Example - imagine we have this rudimentary Gemtext document in the `example.gmi` file:
``` ```
@@ -87,19 +87,19 @@ I write a bit longer Gemtext here to showcase reflow capabilities of Bopher Tool
See ya! See ya!
``` ```
When running `cat example.gmi | bash gmi2map.sh 67`, this file translates to the following Gophermap: When running `cat example.gmi | bash gmi2map.sh 67 0 1`, this file translates to the following Gophermap:
``` ```
$ cat example.gmi | bash gmi2map.sh 67 $ cat example.gmi | bash gmi2map.sh 67
iI write short Gemtext here. ; ; 0 iI write short Gemtext here. ; ; 0
i ; ; 0 i ; ; 0
iI write a bit longer Gemtext here to showcase reflow capabilities ; ; 0 iI write a bit longer Gemtext here to showcase reflow capabilities ; ; 0
iof Bopher Tools' gmi2map.sh script, because it really is cool. ; ; 0 iof Bopher Tools' gmi2map.sh script, because it really is cool. ; ; 0
i ; ; 0 i ; ; 0
1Anyway, why not publish it on Gopher? luxferre happynetbox.com 79 1Anyway, why not publish it on Gopher? luxferre happynetbox.com 79
hOr read my blog on Web... URL:https://chronovir.us ; 0 hOr read my blog on Web... URL:https://chronovir.us ; 0
i ; ; 0 i ; ; 0
iSee ya! ; ; 0 iSee ya! ; ; 0
. .
``` ```
+4 -1
View File
@@ -22,8 +22,11 @@ CRLF=$'\r\n'
[[ -z "$TSPACES" ]] && TSPACES=0 [[ -z "$TSPACES" ]] && TSPACES=0
[[ -z "$DELIM" ]] && DELIM=';' [[ -z "$DELIM" ]] && DELIM=';'
FORMAT_WIDTH=0 # make formatting width distinct from the target reflow width
(( TSPACES > 0 )) && FORMAT_WIDTH="$TARGET_WIDTH" # and only use it if there are trailing spaces
# format strings to use in different situations: # format strings to use in different situations:
reflowfmt="%-$(( LSPACES ))s%-${TARGET_WIDTH}s%-$(( TSPACES ))s\n" # params: smth, line, smth reflowfmt="%-$(( LSPACES ))s%-${FORMAT_WIDTH}s%-$(( TSPACES ))s\n" # params: smth, line, smth
infofmt="i%s${TAB}%s${TAB}%s${TAB}0${CRLF}" # params: line, DELIM, DELIM infofmt="i%s${TAB}%s${TAB}%s${TAB}0${CRLF}" # params: line, DELIM, DELIM
gopherlinkfmt="%s%s${TAB}%s${TAB}%s${TAB}%d${CRLF}" # params: type, name, selector, host, port gopherlinkfmt="%s%s${TAB}%s${TAB}%s${TAB}%d${CRLF}" # params: type, name, selector, host, port
extlinkfmt="h%s${TAB}URL:%s${TAB}%s${TAB}0${CRLF}" # params: name, URL, DELIM extlinkfmt="h%s${TAB}URL:%s${TAB}%s${TAB}0${CRLF}" # params: name, URL, DELIM