Hello Stuart,
Am Freitag, 11. Januar 2013 08:50:31 UTC+1 schrieb Stuart Rackham:
>
>
> The problem comes down to the fact that the link is relative to the root
> document and not the included file. There's no relative version of
> {indir} (relative to {docdir}) so the only way I can see would be to
> synthesize a relative path.
>
> Instead of:
>
> {imagesdir=}{imagesdir?/}{target}
>
> use:
>
> {imagesdir=}{imagesdir?/}{eval:os.path.relpath(r"{docdir={outdir}}",r"{indir={outdir}}")}/{target}
>
>
>
> But it's not the complete answer because the relative path can only be
> calculated if the the two locations lie on a common path.
>
There should be way to synthesize this relative path in a secure way. Isn't
it so that all leaves in a tree
can be linked by a relative path? In the worst case you have to mount up to
the root...
I had a similar problem recently. This is the bash script I am using to
find the shortest path
between 2 absolute ones (I imagine it is much easier in with phyton):
#!/bin/bash
# author Jens Getreu
# version 1.1.0
set -e
declare SCRIPT_NAME="$(basename $0)"
function usage {
echo "Usage: $SCRIPT_NAME -l <absolute path to source file/dir> "
echo " <absolute path to destination dir>"
echo
echo " $SCRIPT_NAME -l links source file/dir"
echo " into destination directory using the shortest possible"
echo " relative path."
echo " It works like "ln -s" but with relative paths."
exit 1
}
# author of this fuction: juancn
# http://stackoverflow.com/questions/2564634/
function find_relpath () {
#echo "find_relpath $# parameters"; echo "$@"
declare base=$1
declare target=$2
declare -a base_part=()
declare -a target_part=()
#Split path elements & canonicalize
OFS="$IFS"; IFS='/'
bpl=0;
for bp in $base; do
case "$bp" in
".");;
"..") let "bpl=$bpl-1" ;;
*) base_part[${bpl}]="$bp" ; let "bpl=$bpl+1";;
esac
done
tpl=0;
for tp in $target; do
case "$tp" in
".");;
"..") let "tpl=$tpl-1" ;;
*) target_part[${tpl}]="$tp" ; let "tpl=$tpl+1";;
esac
done
IFS="$OFS"
#Count common prefix
common=0
for (( i=0 ; i<$bpl ; i++ )); do
if [ "${base_part[$i]}" = "${target_part[$common]}" ] ; then
let "common=$common+1"
else
break
fi
done
#Compute number of directories up
let "updir=$bpl-$common" || updir=0 #if the expression is zero, 'let'
fails
#trivial case (after canonical decomposition)
if [ $updir -eq 0 ]; then
#echo ./
result="./"
fi
#Print updirs
for (( i=0 ; i<$updir ; i++ )); do
#echo -n ../
result="${result}../"
done
#Print remaining path
for (( i=$common ; i<$tpl ; i++ )); do
if [ $i -ne $common ]; then
#echo -n "/"
result="${result}/"
fi
if [ "" != "${target_part[$i]}" ] ; then
#echo -n "${target_part[$i]}"
result="${result}${target_part[$i]}"
fi
done
#One last newline
}
# Start
if [ $# -ne 3 ]||[ "$1" != "-s" ]; then usage;exit 1; fi
#echo "main $# parameters"; echo "$@"
# compute shortest path
find_relpath "$3" "$2" #quotes for not splitting whitespaces
# link it into $3
echo "executing: cd <$3>; ln -s <$result> <.>"
pushd . >/dev/null
cd "$3"
ln -s "$result" .
exit_code=$?
popd >/dev/null
exit $exit_code
>
>
--
You received this message because you are subscribed to the Google Groups
"asciidoc" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/asciidoc?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.