summaryrefslogtreecommitdiff
path: root/modules/md.source.sh
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-05-11 19:54:23 +0100
committerPaul Buetow <git@mx.buetow.org>2021-05-21 05:11:04 +0100
commita453bf2f909e0ea01b0649ce8dc42d54689f738f (patch)
treec8da545ea95fae6a9d6c4658f0318afd3ac58ccf /modules/md.source.sh
parentad828d07774d29f129e1c92ed59baa8c7d75418b (diff)
refactor
Diffstat (limited to 'modules/md.source.sh')
-rw-r--r--modules/md.source.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/modules/md.source.sh b/modules/md.source.sh
new file mode 100644
index 00000000..197bdcf7
--- /dev/null
+++ b/modules/md.source.sh
@@ -0,0 +1,55 @@
+md::make_img () {
+ local link="$1"; shift
+ local descr="$1"; shift
+
+ if [ -z "$descr" ]; then
+ echo "[![$link]($link)]($link) "
+ else
+ echo "[![$descr]($link \"$descr\")]($link) "
+ fi
+}
+
+md::make_link () {
+ local link="$1"; shift
+ local descr="$1"; shift
+
+ grep -F -q '://' <<< "$link" || link=${link/.gmi/.md}
+ test -z "$descr" && descr="$link"
+
+ echo "[$descr]($link) "
+}
+
+md::test () {
+ local line='=> https://example.org'
+ assert::equals "$(generate::make_link md "$line")" \
+ '[https://example.org](https://example.org) '
+
+ line='=> index.md'
+ assert::equals "$(generate::make_link md "$line")" \
+ '[index.md](index.md) '
+
+ line='=> http://example.org Description of the link'
+ assert::equals "$(generate::make_link md "$line")" \
+ '[Description of the link](http://example.org) '
+
+ line='=> http://example.org/image.png'
+ assert::equals "$(generate::make_link md "$line")" \
+ '[![http://example.org/image.png](http://example.org/image.png)](http://example.org/image.png) '
+
+ line='=> http://example.org/image.png Image description'
+ assert::equals "$(generate::make_link md "$line")" \
+ '[![Image description](http://example.org/image.png "Image description")](http://example.org/image.png) '
+}
+
+md::fromgmi () {
+ while IFS='' read -r line; do
+ case "$line" in
+ '=> '*)
+ generate::make_link md "$line"
+ ;;
+ *)
+ echo "$line"
+ ;;
+ esac
+ done
+}