diff options
| author | Paul Buetow <paul@buetow.org> | 2021-05-11 19:53:02 +0100 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2021-05-11 19:53:02 +0100 |
| commit | e19b4a4b4287c10592ac59a09f1ec29293d29c08 (patch) | |
| tree | 7819b6bf43fa3fba35427f85263b14582d4070d3 /lib/md.source.sh | |
| parent | 6d77b5a1540cef0b76246efca262f3392e448e6e (diff) | |
refactor
Diffstat (limited to 'lib/md.source.sh')
| -rw-r--r-- | lib/md.source.sh | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/md.source.sh b/lib/md.source.sh new file mode 100644 index 00000000..197bdcf7 --- /dev/null +++ b/lib/md.source.sh @@ -0,0 +1,55 @@ +md::make_img () { + local link="$1"; shift + local descr="$1"; shift + + if [ -z "$descr" ]; then + echo "[]($link) " + else + echo "[]($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) ' + + line='=> http://example.org/image.png Image description' + assert::equals "$(generate::make_link md "$line")" \ + '[](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 +} |
