Browse Source

Markdown: enhance image URL support

When determining whether or not to add the "--imageroot" or
"--htmlroot" prefix to a relative link, ignore any query string
that may be present.  The fragment (if present) was already
being ignored.

Allow URLs given in reference lines to be wrapped like so:

   [1]: data:image/gif;base64,R0lGODlhFwAXAPMAMf///+7u7t3d3czMzLu7u6qqqp\
        mZmYiIiHd3d2ZmZlVVVURERDMzMyIiIhEREQAAACwAAAAAFwAXAAAExxDISau9Mg\
        She8DURhhHWRLDB26FkSjKqxxFqlbBWOwF4fOGgsCycRkInI+ocEAQNBNWq0caCJ\
        i9aSqqGwwIL4MAsRATeMMMEykYHBLIt7DNHETrAPrBihVwDAh2ansBXygaAj5sa1\
        x7iTUAKomEBU53B0hGVoVMTleEg0hkCD0DJAhwAlVcQT6nLwgHR1liUQNaqgkMDT\
        NWXWkSbS6lZ0eKTUIWuTSbGzlNlkS3LSYksjtPK6YJCzEwNMAgbT9nKBwg6Onq6B\
        EAOw== "title (100x100)"

This facilitates embedding small amounts of data directly in
the source without causing too much difficulty.

Update the documentation to describe this new feature.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
master
Kyle J. McKay 5 years ago
parent
commit
258c5fa653
  1. 5
      Markdown.pl
  2. 31
      syntax.md

5
Markdown.pl

@ -539,7 +539,7 @@ sub _StripLinkDefinitions {
[ ]*
\n? # maybe *one* newline
[ ]*
<?(\S+?)>? # url = $2
<?((?:\S(?:\\\n\s*[^\s"(])?)+?)>? # url = $2
[ ]*
\n? # maybe one newline
[ ]*
@ -556,6 +556,7 @@ sub _StripLinkDefinitions {
my $id = _strip(lc $1); # Link IDs are case-insensitive
my $url = $2;
my $title = _strip($3);
$url =~ s/\\\n\s*//gs;
if ($id ne "") {
$g_urls{$id} = _EncodeAmpsAndAngles($url);
if (defined($title) && $title ne "") {
@ -2258,7 +2259,7 @@ sub _PrefixURL {
$url =~ m,^//, || $url =~ /^[A-Za-z][A-Za-z0-9+.-]*:/;
my $ans = $opt{url_prefix};
$ans = $opt{img_prefix}
if $opt{img_prefix} ne '' && $url =~ m"^[^#]*\.(?:png|gif|jpe?g|svgz?)(?:#|$)"i;
if $opt{img_prefix} ne '' && $url =~ m"^[^#?]*\.(?:png|gif|jpe?g|svgz?)(?:[#?]|$)"i;
return $url unless $ans ne '';
$ans .= '/' if substr($ans, -1, 1) ne '/';
$ans .= substr($url, 0, 1) eq '/' ? substr($url, 1) : $url;

31
syntax.md

@ -1096,6 +1096,37 @@ The first dimension sets the "width" attribute and the second
dimension sets the "height" attribute. The dimensions are then
removed from the "title" attribute.
It's possible to wrap the url when it's specified in a reference.
Both of these examples:
[id]: url/\
t\
o/image
"Optional title"
[id]: url/to/image "Optional title"
Produce identical "img" tags. Only the url can be wrapped and
only when it's in a reference. The backslash ("\") must be the
last character on the line and the next line (after optional
ignored leading whitespace) must contain at least one additional
character that's part of the URL.
This can be useful for data: urls like so:
![image][1]
[1]: data:image/gif;base64,R0lGODlhFwAXAPMAMf///+7u7t3d3czMzLu7u6qqqp\
mZmYiIiHd3d2ZmZlVVVURERDMzMyIiIhEREQAAACwAAAAAFwAXAAAExxDISau9Mg\
She8DURhhHWRLDB26FkSjKqxxFqlbBWOwF4fOGgsCycRkInI+ocEAQNBNWq0caCJ\
i9aSqqGwwIL4MAsRATeMMMEykYHBLIt7DNHETrAPrBihVwDAh2ansBXygaAj5sa1\
x7iTUAKomEBU53B0hGVoVMTleEg0hkCD0DJAhwAlVcQT6nLwgHR1liUQNaqgkMDT\
NWXWkSbS6lZ0eKTUIWuTSbGzlNlkS3LSYksjtPK6YJCzEwNMAgbT9nKBwg6Onq6B\
EAOw== "title (100x100)"
Thus allowing small amounts of image data to be embedded directly in the
source "text" file with minimal fuss.
- - - - -

Loading…
Cancel
Save