X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=macros%2Finclude;h=f3005849cb2c9be5bdba8ceb57bca2e73031a5b0;hb=fe5a022bee36488bb1b4ad923bd4b77e70f9f054;hp=d35c2a30c625a5b9938971a9411e9fc6978a948a;hpb=922181c682dc5d499eea65ae502e894e88e07f84;p=shellwiki diff --git a/macros/include b/macros/include index d35c2a3..f300584 100755 --- a/macros/include +++ b/macros/include @@ -1,14 +1,24 @@ #!/bin/sh +# Copyright 2022 Paul Hänsch +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +# IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + . "$_EXEC/cgilite/cgilite.sh" . "$_EXEC/acl.sh" . "$_EXEC/tools.sh" -from=1 -to=\$ -rev='' -items=\$ -path_info="$PATH_INFO" +from='1'; to='$'; rev=''; items='$'; hl=0; link='true' while [ $# -gt 0 ]; do case $1 in --from) from="$2"; shift 2;; @@ -18,6 +28,8 @@ while [ $# -gt 0 ]; do case $1 in --items) items="$2"; shift 2;; items=*) items="${1#*=}"; shift 1;; --rev|--reverse) rev="-r"; shift 1;; + --nolink) link=""; shift 1;; + --hl|-hl) hl=$2; shift 2;; *) page="$1"; shift 1;; esac; done @@ -25,7 +37,7 @@ if ! printf %s\\n "$from" |grep -qEx '[0-9]+|/([^/\\]|\\/|\\.)*/'; then debug 'Include macro invalid argument: "from"' exit 1 fi -if ! printf %s\\n "$to" |grep -qEx '[0-9]+|/([^/\\]|\\/|\\.)*/'; then +if ! printf %s\\n "$to" |grep -qEx '\$|[0-9]+|/([^/\\]|\\/|\\.)*/'; then debug 'Include macro Invalid argument: "to"' exit 1 fi @@ -38,21 +50,22 @@ page_glob "$page" \ | sort $rev \ | sed "${items}q" \ | while read glob; do - case $glob in - /*) export PATH_INFO="$(PATH "$glob")";; - *) export PATH_INFO="$(PATH "$path_info/$glob")";; - esac - acl_read || continue - if [ -f "$_DATA/pages/$PATH_INFO/#page.md" ]; then - mdfile="$_DATA/pages/$PATH_INFO/#page.md" - elif [ -f "$_EXEC/pages/$PATH_INFO/#page.md" ]; then - mdfile="$_EXEC/pages/$PATH_INFO/#page.md" - else - continue - fi - printf '
' "$(HTML "$glob")" - refpfx="$(HTML "$glob" |sed 's;[\;&\;];\\&;g')" - ( cd -- "${mdfile%/*}" + page="$(page_abs "$glob")" + acl_read "$page" || continue + mdfile="$(mdfile "$page")" || continue + hglob="$(HTML "$glob")" + refpfx="$(printf %s\\n "$hglob" |sed 's;[\;&\;];\\&;g')" + [ "$link" ] \ + && printf '
+ %s +
' \ + "${hglob}" "${hglob}" "${hglob}" \ + || printf '
+
' \ + "${hglob}" + ( # PATH_INFO may be used by macros in the included page + export PATH_INFO="$page" + cd -- "${mdfile%/*}/" sed -n "${from},${to}p" <"$mdfile" \ | md \ | grep -vx '' @@ -60,6 +73,39 @@ page_glob "$page" \ s;(<[^>]+ )(href|src)="([^"]+://[^"]*|[mM][aA][iI][lL][tT][oO]:[^"]*)"([^>]*>);\1\2="/#safe/\3"\4;g s;(<[^>]+ )(href|src)="([^#/"][^"]*)"([^>]*>);\1\2="'"${refpfx}"'\3"\4;g s;(<[^>]+ )(href|src)="/#safe/([^"]*)"([^>]*>);\1\2="\3"\4;g - ' - printf '
' + ' | case $hl in + 1) sed -E 's;();\16\2;g; + s;();\15\2;g; + s;();\14\2;g; + s;();\13\2;g; + s;();\12\2;g; + ';; + 2) sed -E 's;();\16\2;g; + s;();\16\2;g; + s;();\15\2;g; + s;();\14\2;g; + s;();\13\2;g; + ';; + 3) sed -E 's;();\16\2;g; + s;();\16\2;g; + s;();\16\2;g; + s;();\15\2;g; + s;();\14\2;g; + ';; + 4) sed -E 's;();\16\2;g; + s;();\16\2;g; + s;();\16\2;g; + s;();\16\2;g; + s;();\15\2;g; + ';; + 5|[6789]) + sed -E 's;();\16\2;g; + s;();\16\2;g; + s;();\16\2;g; + s;();\16\2;g; + s;();\16\2;g; + ';; + *) cat;; + esac + printf '
' done