[PATCH 1/1] filters: in markdown get images from their plain url

Christian Hesse mail at eworm.de
Thu Apr 17 13:42:32 CEST 2014


URLs starting with two slashes or containing '://' are expected to be
absolut and therefore not modified. Relative URLs are prefixed with
'../plain/' to get a plain version from cgit.
---
 filters/html-converters/resources/markdown.pl | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/filters/html-converters/resources/markdown.pl b/filters/html-converters/resources/markdown.pl
index 34337c2..365f8b6 100755
--- a/filters/html-converters/resources/markdown.pl
+++ b/filters/html-converters/resources/markdown.pl
@@ -925,6 +925,7 @@ sub _DoImages {
 			my $url = $g_urls{$link_id};
 			$url =~ s! \* !$g_escape_table{'*'}!gx;		# We've got to encode these to avoid
 			$url =~ s!  _ !$g_escape_table{'_'}!gx;		# conflicting with italics/bold.
+			$url = "../plain/$url" unless $url =~ m/(^|:)\/\//;
 			$result = "<img src=\"$url\" alt=\"$alt_text\"";
 			if (defined $g_titles{$link_id}) {
 				my $title = $g_titles{$link_id};
@@ -977,6 +978,7 @@ sub _DoImages {
 		$title    =~ s/"/"/g;
 		$url =~ s! \* !$g_escape_table{'*'}!gx;		# We've got to encode these to avoid
 		$url =~ s!  _ !$g_escape_table{'_'}!gx;		# conflicting with italics/bold.
+		$url = "../plain/$url" unless $url =~ m/(^|:)\/\//;
 		$result = "<img src=\"$url\" alt=\"$alt_text\"";
 		if (defined $title) {
 			$title =~ s! \* !$g_escape_table{'*'}!gx;
-- 
1.9.2



More information about the CGit mailing list