From f5db8d1a77c2d6f5edecc0683cb1db1ce9fd9efa Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 3 Aug 2015 15:00:49 +0100 Subject: [PATCH] Link underscore fixes. --- Webperl/Template.pm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Webperl/Template.pm b/Webperl/Template.pm index ced0ecc..7766611 100644 --- a/Webperl/Template.pm +++ b/Webperl/Template.pm @@ -884,7 +884,7 @@ sub format_time { $datestr =~ s/(\d+)\s*%o/ordinal($1)/ge; # Trim leading zeros, as they are pointless - $datestr =~ s/(\A|\D)0+([1-9])/$1$2/g; + $datestr =~ s/(\A|\b)0+([1-9])/$1$2/g; return $datestr; } @@ -1035,6 +1035,9 @@ sub html_to_markdown { # Sometimes there are bizarre <>s left in the content, dunno why... $body =~ s|<>||g; + # Fix underscores in links + $body =~ s|\[([^\]+)\]|_fix_link_underscores($1)|g; + $body =~ s|\n\n+|\n\n|g; my $imglist = ""; @@ -1080,6 +1083,14 @@ sub _markdown_underline { } +sub _fix_link_underscores { + my $text = shift; + + $text =~ s/\\_/_/g; + return $text; +} + + ## @method $ bytes_to_human($bytes, $long) # Convenience wrappper around humanise_bytes for backwards compatibility. #