3 . "$_EXEC/cgilite/cgilite.sh"
11 path_info="$PATH_INFO"
13 while [ $# -gt 0 ]; do case $1 in
14 --from) from="$2"; shift 2;;
15 from=*) from="${1#*=}"; shift 1;;
16 --to) to="$2"; shift 2;;
17 to=*) to="${1#*=}"; shift 1;;
18 --items) items="$2"; shift 2;;
19 items=*) items="${1#*=}"; shift 1;;
20 --rev|--reverse) rev="-r"; shift 1;;
21 *) page="$1"; shift 1;;
24 if ! printf %s\\n "$from" |grep -qEx '[0-9]+|/([^/\\]|\\/|\\.)*/'; then
25 debug 'Include macro invalid argument: "from"'
28 if ! printf %s\\n "$to" |grep -qEx '[0-9]+|/([^/\\]|\\/|\\.)*/'; then
29 debug 'Include macro Invalid argument: "to"'
32 if ! printf %s\\n "$items" |grep -qEx '\$|[0-9]+'; then
33 debug 'Include macro Invalid argument: "items"'
37 printf '<div class="macro include wrapper">'
43 /*) export PATH_INFO="$(PATH "$glob")";;
44 *) export PATH_INFO="$(PATH "$path_info/$glob")";;
47 if [ -f "$_DATA/pages/$PATH_INFO/#page.md" ]; then
48 mdfile="$_DATA/pages/$PATH_INFO/#page.md"
49 elif [ -f "$_EXEC/pages/$PATH_INFO/#page.md" ]; then
50 mdfile="$_EXEC/pages/$PATH_INFO/#page.md"
54 hglob="$(HTML "$glob")"
55 refpfx="$(printf %s\\n "$hglob" |sed 's;[\;&\;];\\&;g')"
56 printf '<div class="macro include page"><article class="include" id="include_%s">' "${hglob}"
57 ( cd -- "${mdfile%/*}"
58 sed -n "${from},${to}p" <"$mdfile" \
62 s;(<[^>]+ )(href|src)="([^"]+://[^"]*|[mM][aA][iI][lL][tT][oO]:[^"]*)"([^>]*>);\1\2="/#safe/\3"\4;g
63 s;(<[^>]+ )(href|src)="([^#/"][^"]*)"([^>]*>);\1\2="'"${refpfx}"'\3"\4;g
64 s;(<[^>]+ )(href|src)="/#safe/([^"]*)"([^>]*>);\1\2="\3"\4;g
67 printf '<a class="include link" href="%s">%s</a>' "${hglob}" "${hglob}"