gitdown icon indicating copy to clipboard operation
gitdown copied to clipboard

When GIT variable is empty $imgpath can start with //

Open ahendriksen opened this issue 9 years ago • 0 comments

Hi,

Happy user of gitdown here. I don't use for a github project though. I use it on gitlab.

When I insert a

[diagram]
---->
[/diagram/

block, I want the url to be as follows (I guess gitlab image inclusion uses different urls)

<img src="images/README_1.png" alt="1">

When I set branch and prebranch to empty

.set BRANCH=
.set PREBRANCH=

I get instead:

<img src="//images/README_1.png" alt="1">

I was able to fix it by removing any slashed in front of the final url as follows:

diff --git a/bin/gitdown b/bin/gitdown
index 653d092..9bbabd9 100755
--- a/bin/gitdown
+++ b/bin/gitdown
@@ -125,13 +125,14 @@ while ($line < @input) {
             $imgpath = $symbols{GIT}.'/';
             # allow double slash after : for url
             $imgpath =~ s|(?<!:)/+|/|g;
-
             my $subpath .= "$symbols{PREBRANCH}/$symbols{BRANCH}/$symbols{SUBDIR}/images/";
             # remove starting /
             $subpath =~ s|^/||;
             # remove double /
             $subpath =~ s|/+|/|g;
             $imgpath .= $subpath;
+            # remove starting /
+            $imgpath =~ s|^/+||;
         }
         elsif (/^\.toc(\s+([1-9]))?/) {
             #   Determine top level in text after .toc

I am sorry that this is not a 'pull request'. I am not well acquainted with github..

ahendriksen avatar Nov 20 '16 17:11 ahendriksen