• Hi
    Everything is working apart from modifying the image url in the post.
    The post is uploading, the images are uploading and the frontmatter is working.

    But the url of the images doesn’t change from…
    _images/
    …to the location of the image.

    I have the Classic Editor set as default. Here is the code in the post for an image…

    <figure class="wp-block-image size-full">
    <img src="_images/image-file-name.png" alt="" />
    </figure>

    I checked here and on GitHub and I couldn’t find a solution to the problem. Could it perhaps be a conflict with another plugin.

    Cheers
    Mac2Net

    • This topic was modified 2 months, 3 weeks ago by mac-2-net.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter mac-2-net

    (@mactwonet)

    I sort of solved the problem.

    My Markdown editor – Zettir – doesn’t want a forward slash in front of _images so I altered the code in parsedown.php to ignore he missing /

    Maybe you should add an option for this.

    I like Zettir for Markdown because unlike other apps I tested, like Bear and MWeb, it stores files in the file system instead of a proprietary format or database.

    • This reply was modified 2 months, 3 weeks ago by mac-2-net.
    Plugin Author vaakash

    (@vaakash)

    Hi @mactwonet,

    Thanks for using GIW plugin abnd glad you figured out the issue.

    GIW expects the images directory to be at the root and / indicates the project root. If the “editor” of your choice opens the root project folder then /_images/image.jpg will work correctly. Without slash it means to pick the _images folder from the current directory the markdown file is written in. If the markdown preview works without the images being broken in github website online, then everything is working as expected.

    You can see a sample repo here – https://github.com/vaakash/test

    Thanks,

    Aakash

    Thread Starter mac-2-net

    (@mactwonet)

    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.
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.