Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Michelf/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,13 @@ protected function _doImages_reference_callback($matches) {
if (isset($this->urls[$link_id])) {
$url = $this->encodeURLAttribute($this->urls[$link_id]);
$result = "<img src=\"$url\" alt=\"$alt_text\"";
if(file_exists($url))
{
list($width, $height, $type, $attr) = getimagesize($url);
if(isset($width)) $result .= " width=\"$width\"";
if(isset($height)) $result .= " height=\"$height\"";
if(isset($width) && isset($height)) $result .= " loading=\"lazy\"";
}
if (isset($this->titles[$link_id])) {
$title = $this->titles[$link_id];
$title = $this->encodeAttribute($title);
Expand Down Expand Up @@ -893,6 +900,13 @@ protected function _doImages_inline_callback($matches) {
$alt_text = $this->encodeAttribute($alt_text);
$url = $this->encodeURLAttribute($url);
$result = "<img src=\"$url\" alt=\"$alt_text\"";
if(file_exists($url))
{
list($width, $height, $type, $attr) = getimagesize($url);
if(isset($width)) $result .= " width=\"$width\"";
if(isset($height)) $result .= " height=\"$height\"";
if(isset($width) && isset($height)) $result .= " loading=\"lazy\"";
}
if (isset($title)) {
$title = $this->encodeAttribute($title);
$result .= " title=\"$title\""; // $title already quoted
Expand Down
14 changes: 14 additions & 0 deletions Michelf/MarkdownExtra.php
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,13 @@ protected function _doImages_reference_callback($matches) {
if (isset($this->urls[$link_id])) {
$url = $this->encodeURLAttribute($this->urls[$link_id]);
$result = "<img src=\"$url\" alt=\"$alt_text\"";
if(file_exists($url))
{
list($width, $height, $type, $attr) = getimagesize($url);
if(isset($width)) $result .= " width=\"$width\"";
if(isset($height)) $result .= " height=\"$height\"";
if(isset($width) && isset($height)) $result .= " loading=\"lazy\"";
}
if (isset($this->titles[$link_id])) {
$title = $this->titles[$link_id];
$title = $this->encodeAttribute($title);
Expand Down Expand Up @@ -1064,6 +1071,13 @@ protected function _doImages_inline_callback($matches) {
$alt_text = $this->encodeAttribute($alt_text);
$url = $this->encodeURLAttribute($url);
$result = "<img src=\"$url\" alt=\"$alt_text\"";
if(file_exists($url))
{
list($width, $height, $type, $attr) = getimagesize($url);
if(isset($width)) $result .= " width=\"$width\"";
if(isset($height)) $result .= " height=\"$height\"";
if(isset($width) && isset($height)) $result .= " loading=\"lazy\"";
}
if (isset($title) && $title_quote) {
$title = $this->encodeAttribute($title);
$result .= " title=\"$title\""; // $title already quoted
Expand Down