Skip to content
Snippets Groups Projects
Commit 99e719d9 authored by Jared Hancock's avatar Jared Hancock
Browse files

Fix external image in an inline <a> element

htmLawed stripped/discarded <div> tags nested inside inline tags such as
<a>. The previous replacement engine would replace <img> tags with <div>
tags and would cause the HTML to be corrupted by htmLawed.

This patch uses <span> tags which have CSS rules to be displayed as
inline-blocks. This should stay truer to the normal sizing and placement of
the original <img> tag.
parent e4cad914
Branches
Tags
No related merge requests found
...@@ -280,7 +280,7 @@ class Format { ...@@ -280,7 +280,7 @@ class Format {
function($match) { function($match) {
// Drop embedded classes -- they don't refer to ours // Drop embedded classes -- they don't refer to ours
$match = preg_replace('/class="[^"]*"/', '', $match); $match = preg_replace('/class="[^"]*"/', '', $match);
return sprintf('<div %s class="non-local-image" data-%s %s></div>', return sprintf('<span %s class="non-local-image" data-%s %s></span>',
$match[1], $match[2], $match[3]); $match[1], $match[2], $match[3]);
}, },
$text); $text);
...@@ -354,7 +354,7 @@ class Format { ...@@ -354,7 +354,7 @@ class Format {
} }
// Images which are external are rewritten to <div // Images which are external are rewritten to <div
// data-src='url...'/> // data-src='url...'/>
elseif ($e == 'div' && $a && isset($a['data-src'])) elseif ($e == 'span' && $a && isset($a['data-src']))
$a['data-src'] = 'l.php?url='.urlencode($a['data-src']) $a['data-src'] = 'l.php?url='.urlencode($a['data-src'])
.'&amp;auth='.$token; .'&amp;auth='.$token;
// URLs for videos need to route too // URLs for videos need to route too
...@@ -373,7 +373,7 @@ class Format { ...@@ -373,7 +373,7 @@ class Format {
}, },
'schemes' => 'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; *:file, http, https; src: cid, http, https, data', 'schemes' => 'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; *:file, http, https; src: cid, http, https, data',
'elements' => '*+iframe', 'elements' => '*+iframe',
'spec' => 'div=data-src,width,height', 'spec' => 'span=data-src,width,height',
); );
return Format::html($text, $config); return Format::html($text, $config);
} }
......
...@@ -174,7 +174,7 @@ showImagesInline = function(urls, thread_id) { ...@@ -174,7 +174,7 @@ showImagesInline = function(urls, thread_id) {
// Optionally show external images // Optionally show external images
$('.thread-entry').each(function(i, te) { $('.thread-entry').each(function(i, te) {
var extra = $(te).find('.textra'), var extra = $(te).find('.textra'),
imgs = $(te).find('div.non-local-image[data-src]'); imgs = $(te).find('.non-local-image[data-src]');
if (!extra) return; if (!extra) return;
if (!imgs.length) return; if (!imgs.length) return;
extra.append($('<a>') extra.append($('<a>')
......
...@@ -388,7 +388,7 @@ jQuery(function($) { ...@@ -388,7 +388,7 @@ jQuery(function($) {
// Optionally show external images // Optionally show external images
$('.thread-entry').each(function(i, te) { $('.thread-entry').each(function(i, te) {
var extra = $(te).find('.textra'), var extra = $(te).find('.textra'),
imgs = $(te).find('div.non-local-image[data-src]'); imgs = $(te).find('.non-local-image[data-src]');
if (!extra) return; if (!extra) return;
if (!imgs.length) return; if (!imgs.length) return;
extra.append($('<a>') extra.append($('<a>')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment