Actually GitHub works both with and without /
in front of _images
.
The problem is in the plugin code which hardcodes the /
in parsedown.php in the following code
public function inlineImage( $excerpt ){
$image_data = parent::inlineImage( $excerpt );
if( empty( $image_data ) ){
return $image_data;
}
$image_url = $image_data[ 'element' ][ 'attributes' ][ 'src' ];
// Check if the image URL is relative to the root and is under the _images directory
$first_character = substr( $image_url, 0, 1 );
if( $first_character == '/' ){
$parts = explode( '/', $image_url ); // Expecting a path like /_images/pic1.jpg
if( count( $parts ) < 3 ){ // If less than 3 parts then continue with original URL
return $image_data;
}
if( $parts[1] != '_images' ){ // If the directory is not _images then continue with original
return $image_data;
}
/**
* Uploaded images key contains the full relative path of the image file and does NOT start with slash.
* Removing the prefix slash in $image_url to fetch the details.
*/
$image_url = ltrim( $image_url, '/' );
// Get the attachment URL from the uploaded images cache list
if( array_key_exists( $image_url, $this->uploaded_images ) ){
$image_data[ 'element' ][ 'attributes' ][ 'src' ] = $this->uploaded_images[ $image_url ][ 'url' ];
// Add the image ID class to mimic default behavior
$image_id_class = 'wp-image-' . $this->uploaded_images[ $image_url ][ 'id' ];
if( array_key_exists( 'class', $image_data[ 'element' ][ 'attributes' ] ) ){
$image_data[ 'element' ][ 'attributes' ][ 'class' ] .= ' ' . $image_id_class;
}else{
$image_data[ 'element' ][ 'attributes' ][ 'class' ] = $image_id_class;
}
}
}
return $image_data;
}
-
This reply was modified 2 months, 2 weeks ago by
mac-2-net.