3 # Copyright 2022 Paul Hänsch
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15 # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . "$_EXEC/cgilite/cgilite.sh"
21 from='1'; to='$'; rev=''; items='$'; hl=0; link='true'
23 while [ $# -gt 0 ]; do case $1 in
24 --from) from="$2"; shift 2;;
25 from=*) from="${1#*=}"; shift 1;;
26 --to) to="$2"; shift 2;;
27 to=*) to="${1#*=}"; shift 1;;
28 --items) items="$2"; shift 2;;
29 items=*) items="${1#*=}"; shift 1;;
30 --rev|--reverse) rev="-r"; shift 1;;
31 --nolink) link=""; shift 1;;
32 --hl|-hl) hl=$2; shift 2;;
33 *) page="$1"; shift 1;;
36 if ! printf %s\\n "$from" |grep -qEx '[0-9]+|/([^/\\]|\\/|\\.)*/'; then
37 debug 'Include macro invalid argument: "from"'
40 if ! printf %s\\n "$to" |grep -qEx '\$|[0-9]+|/([^/\\]|\\/|\\.)*/'; then
41 debug 'Include macro Invalid argument: "to"'
44 if ! printf %s\\n "$items" |grep -qEx '\$|[0-9]+'; then
45 debug 'Include macro Invalid argument: "items"'
53 page="$(page_abs "$glob")"
54 acl_read "$page" || continue
55 mdfile="$(mdfile "$page")" || continue
56 hglob="$(HTML "$glob")"
57 refpfx="$(printf %s\\n "$hglob" |sed 's;[\;&\;];\\&;g')"
59 && printf '<div class="macro include">
60 <a class="include link" href="%s">%s</a>
61 <article class="include" id="include_%s">' \
62 "${hglob}" "${hglob}" "${hglob}" \
63 || printf '<div class="macro include">
64 <article class="include" id="include_%s">' \
66 ( # PATH_INFO may be used by macros in the included page
67 export PATH_INFO="$page"
69 sed -n "${from},${to}p" <"$mdfile" \
73 s;(<[^>]+ )(href|src)="([^"]+://[^"]*|[mM][aA][iI][lL][tT][oO]:[^"]*)"([^>]*>);\1\2="/#safe/\3"\4;g
74 s;(<[^>]+ )(href|src)="([^#/"][^"]*)"([^>]*>);\1\2="'"${refpfx}"'\3"\4;g
75 s;(<[^>]+ )(href|src)="/#safe/([^"]*)"([^>]*>);\1\2="\3"\4;g
77 1) sed -E 's;(<h|</h)5( |>);\16\2;g;
78 s;(<h|</h)4( |>);\15\2;g;
79 s;(<h|</h)3( |>);\14\2;g;
80 s;(<h|</h)2( |>);\13\2;g;
81 s;(<h|</h)1( |>);\12\2;g;
83 2) sed -E 's;(<h|</h)5( |>);\16\2;g;
84 s;(<h|</h)4( |>);\16\2;g;
85 s;(<h|</h)3( |>);\15\2;g;
86 s;(<h|</h)2( |>);\14\2;g;
87 s;(<h|</h)1( |>);\13\2;g;
89 3) sed -E 's;(<h|</h)5( |>);\16\2;g;
90 s;(<h|</h)4( |>);\16\2;g;
91 s;(<h|</h)3( |>);\16\2;g;
92 s;(<h|</h)2( |>);\15\2;g;
93 s;(<h|</h)1( |>);\14\2;g;
95 4) sed -E 's;(<h|</h)5( |>);\16\2;g;
96 s;(<h|</h)4( |>);\16\2;g;
97 s;(<h|</h)3( |>);\16\2;g;
98 s;(<h|</h)2( |>);\16\2;g;
99 s;(<h|</h)1( |>);\15\2;g;
102 sed -E 's;(<h|</h)5( |>);\16\2;g;
103 s;(<h|</h)4( |>);\16\2;g;
104 s;(<h|</h)3( |>);\16\2;g;
105 s;(<h|</h)2( |>);\16\2;g;
106 s;(<h|</h)1( |>);\16\2;g;
110 printf '</article></div>'