Page 1 of 1

Broken images in Markdown viewer

Posted: 17 Sep 2019, 22:01
by zorglups
Hello,

Happy to see support for Markdown in Altap Salamander.

The viewer shows broken images.

If I right click and select "View Source", notepad opens and I see that the image HTML code is this:
<img src=".%5CzZ_assets%5CAnki.assets%5C1546471044201.png" alt="1546471044201" />

If I save the "viewed source" into an html file and view that html file with the Altap Salamander viewer, the image displays fine.

Is that a known problem ?

Thanks,

Pierre

Re: Broken images in Markdown viewer

Posted: 18 Sep 2019, 16:59
by SvA
The viewer uses the about: scheme. Since your url did not use it's own scheme, the viewer could not locate the resource.

It's probably the same reason pressing F5 leaves you with an empty screen.

@Altap: maybe add a <base>-tag pointing to the .md's folder in order to fix @zorglups' problem?

Re: Broken images in Markdown viewer

Posted: 27 Nov 2019, 19:12
by SvA
I now tried to add an image myself. Knowing that a relative path does not work I tried an absolute path, including file: scheme. This cause the resulting src property to be the empty string:

Code: Select all

![Skizze](file://HOST/SHARE/Path/image.jpg)
results in

Code: Select all

<img src="" alt="Skizze" />
Is this a bug or a security feature? Do I need to set up a web server in order to be able to embed pictures?

Re: Broken images in Markdown viewer

Posted: 20 Jan 2025, 18:27
by powerlicht
I couldn't get the relative path to work either. I've created something that allows me to repair the local image links again and again. They have to be present in the MarkDown files as an absolute local path.


It took a moment for me to get the regex for search and replace to work, but it works great: Demo > regexstorm.net
2025-01-20regex.png
2025-01-20regex.png (29.08 KiB) Viewed 14950 times

The local image path must not contain any spaces!


I created a test folder on drive Y using:
2025-01-20_175801.png
2025-01-20_175801.png (1.15 KiB) Viewed 14950 times

I also added my batch file to the structure, in the same location as the MarkDown files
2025-01-20_tree.png
2025-01-20_tree.png (9.61 KiB) Viewed 14950 times

Drag and drop one or more directories onto the batch file. A menu appears, which then allows you to use the new image directory for the image link. A directory called 'fixed' is automatically created and, if it already exists, generated with a consecutive number. The new Markdown files are stored there.
2025-01-20_182147.png
2025-01-20_182147.png (127.66 KiB) Viewed 14950 times

MD-Helper_fix-ImagePath___DragDrop-ImagePath.cmd
<# :

  @echo off
  :: Path-List transfer to powershell as UniCode!!!
	:: ECHO ---------------------------------------------------------
	:: ECHO.ECHO %%*:
	:: ECHO %*
	ECHO %* | clip 
	:: ECHO ---------------------------------------------------------
	:: ECHO.Powershell:
    powershell /nologo /noprofile /ExecutionPolicy bypass /command ^
         "&{[ScriptBlock]::Create((cat """%~f0""") -join [Char[]]10).Invoke(($args = '%*'))}"
    ECHO.
  pause
  pause
  pause
  pause
  pause
  pause
  pause
  pause
  REM exit /b
#>

$text = @{
    WindowTitleStarttitle  = "Fix absolute local image paths in MD-Files"
    WindowTitleMenuIMGpath = "select Image-Folder"

    #write-host messages:
    wh__NotPathFound  = "no Path(s) found ... Drop a path 'A:\' or 'Z:\abc\md-images'...`nPath with SPACES is forbidden. Spaces in Path is Problem for local-path"

    #write-verbose messages
    wv__MDfileOK      = "MD-FilePath is ok!"
    wv__ParsePath     = "Parse Path-Info from Drop-List"
    wv__SelectedIMGpath_0 = "selected MD-Image-Path"

    #write-warning messages
    ww__MDfileFail    = "MD-FilePath is not working!"
}

#region definition HOST / ISE
    if ($host.name -eq 'ConsoleHost'){ 
        $host.UI.RawUI.WindowTitle = $text.WindowTitleStarttitle 
        $host.PrivateData.WarningBackgroundColor = "black"
        $host.PrivateData.WarningForegroundColor = "red"
        $host.PrivateData.VerboseBackgroundColor = "black"
        $host.PrivateData.VerboseForegroundColor = "darkcyan"        
        $location = @{ hier = (get-item '.')}
    }else{ 
        # ISE...   
    }
#endregion


#region functions
    function Main {    
        [cmdletbinding()]param()

        # return from ClipBoard only DirectoryPaths
        $pfade = get-Paths-from-clipbaord
        Write-Verbose $text.wv__ParsePath

        if ($pfade.count -gt 0){
            # return only exactly MD-DirectoryPaths    
            $mdPfade = getPathForMDLinks -pathListe $pfade -Verbose
        }else{
            Write-host -b DarkRed -f White $text.wh__NotPathFound
        }

        if($mdPfade.count -ge 1) {
            # MD-Files
            $md_files = Get-ChildItem $location.hier -file | ? {$_.Extension -eq '.md' }

            # Menu
            write-host -b DarkCyan -f black ("`nMenu-Auswahl f$([char]252)r IMG-Pfad ... {0} MD-Files gefunden" -f $md_files.count)    
            $host.UI.RawUI.WindowTitle = $text.WindowTitleMenuIMGpath + " f$([char]252)r MD-Files: [" + $location.hier + ']'
            do {
                menu-aus-parameterListe-erstellen -Text_fuer_Menuzeilen $mdPfade.fullname    
                $menu_auswahl = read-host -Prompt "`n"
            }while(1..$mdPfade.count -notcontains $menu_auswahl)
            Write-Verbose ("$($text.wv__SelectedIMGpath_0) [$($mdPfade[$menu_auswahl-1])]"  )

            # IMG-Path
            $imagePath = get-item $mdPfade[$menu_auswahl-1].fullname

            # 1 / 5 - create new MD-File-Folder 'fixed[1-9]+' 
            $fixed_path = create-folder-mit-fortlaufender-Nummer -savePath (Join-Path -Path $location.hier -ChildPath "fixed" )
            
            # 2 / 5 - Foldername for 'fixed[1-9]+'
            # file system refresh to slow? if now created a folder 'fixed3' and this function found old 'fixed2'
            # fixed_path = get-folder-mit-fortlaufender-Nummer -Path (Join-Path -Path $location.hier -ChildPath "fixed" )
            # 
            Write-Verbose "fixed_path [$($fixed_path)]" # ;  Write-Verbose "locat_hier [$($location.hier)]"

            # 3 / 5 - read original-md-file > replace img-path > write new-md-file into new 'fixed'-Folder
            $imagePath = (Join-Path -Path $imagePath -ChildPath "") -replace '\\','//'
            foreach ($mdf in $md_files)
            {
                #[System.IO.File]::ReadLines($mdf)

                #$reader = New-Object System.IO.StreamReader($mdf.FullName  , [System.Text.Encoding]::Unicode)
                $reader = New-Object System.IO.StreamReader($mdf.FullName  )
                #$writer = New-Object System.IO.StreamWriter("$( Join-Path -Path $fixed_path -ChildPath $mdf.name )", $true, [System.Text.Encoding]::Unicode) # the true means to "append"
                $writer = New-Object System.IO.StreamWriter("$( Join-Path -Path $fixed_path -ChildPath $mdf.name )", $true) # the true means to "append"
                            
                while ($reader.Peek() -ge 0) {
                    $tmp = $reader.ReadLine()
                    # ---- $tmp = $tmp -replace '(?<=!\[.*?\]\()(?<Path>.*?)(?=[^\/\\]*?\))', $imagePath
                    $patt = '(?<=!?\[.*?\]\()(?<Path>[a-z]:.*?)(?=[^\/\\]*?\))'
                    $tmp = $tmp -replace $patt , $imagePath
                    <# replace :
                            sample-1: ![system.io.directory_getFreeDriveLetter.png](C:\Helfer-Powershell\Hilfe\images\system.io.directory_getFreeDriveLetter.png)
                            sample-2: ![system.io.directory_getFreeDriveLetter.png](C:/Helfer-Powershell/Hilfe/images/system.io.directory_getFreeDriveLetter.png)
                            sample-3: ![system.io.directory_getFreeDriveLetter.png](C:\\Helfer-Powershell\\Hilfe\\images\\system.io.directory_getFreeDriveLetter.png)
                            sample-4: ![system.io.directory_getFreeDriveLetter.png](C://Helfer-Powershell//Hilfe//images//system.io.directory_getFreeDriveLetter.png)
                        to:
                      sample-1+2+3+4: ![system.io.directory_getFreeDriveLetter.png](Y://images/system.io.directory_getFreeDriveLetter.png)
                    #>
                    $writer.writeline($tmp )
                }

                $reader.Close()
                $writer.Close()

            } # END - foreach write new md-files
        } # END - if $mdpfade.count  
    } # END - function Main


    
    function get-Paths-from-clipbaord {  
        # FilePaths from Drag'nDrop over Batch-File    
        $paths = [System.Windows.Forms.Clipboard]::GetText() -replace '"' | 
            Where-Object   { $_ -match '[a-z]:' } | 
            ForEach-Object { ($_ -split $Matches[0] ).trim() -join "`n$($Matches[0])" -split '\n' } | 
            Where-Object   { $_ -ne "" } | 
            Where-Object   { [System.IO.Directory]::Exists($_) } |  
            ForEach-Object { Get-Item $_ }
        return $paths
    }


    function getPathForMDLinks {
        [CMDletbinding()]
        param ($pathListe)

        # $ret = $pathListe | ? { $_ -notmatch '[ ]' } 
        $ret = $pathListe | <# ? { [System.IO.Directory]::Exists($_)} | #>
        % {
            if ( $_ -notmatch '[ ]' ){
                Write-Verbose "$($text.wv__MDfileOK) [$($_.fullname)]"
                $_
            }else{
                Write-Warning "$($text.ww__MDfileFail) [$($_.fullname)]"
            }
        }
    
        return $ret
    }

    function menu-aus-parameterListe-erstellen {
        param($Text_fuer_Menuzeilen, $Text_fuer_Exit_Menuzeile)
    #    write-host -b darkblue -f white ("`nW$([char]228)hle eine Ziffer aus ("   ) -non 
    #    write-host -b Black    -f Green ("0"   ) -non
    #    write-host -b darkblue -f white (" = Exit):"   )
        $i = 0; 
        $leer    = " "
        $Text_fuer_Menuzeilen_intern = @("")
        $Text_fuer_Menuzeilen_intern += $Text_fuer_Menuzeilen
        # write-host -b DarkGreen (($Text_fuer_Menuzeilen_intern | sort {$_.length})[-1].length)
        $max_spc = (($Text_fuer_Menuzeilen_intern, $Text_fuer_Exit_Menuzeile | sort {$_.length})[-1].length) +1
        # if ($max_spc -lt 30) {$max_spc = 30}
        
        $spaces  = (" "*$max_spc)
        $exit    =  $Text_fuer_Exit_Menuzeile
                         # -1 > 1 Space ganz vorne
                         # -1 > 1 Space ganz hinten
                         # -$leer.length  > Abstand vor+hinter dem Wort, welches mittig sein soll
                         # -Wortlaenge > 
                         # exit_weite > welche dann als Leerraumfueller vorher und Nachher zerteilt wird
        $exit_weite = ($max_spc -1  -$leer.Length -$leer.Length -$exit.Length )
        $exit_fuer_menu =   "{0}{2}{3}{2}{1}" -f 
            ("-" *([math]::Truncate($exit_weite/2)  + ($exit_weite % 2))) , 
            ("-" *([math]::Truncate($exit_weite/2) )) , 
            $leer , 
            $exit

    
        function ZeilenMenuAufbauen {
            param ($zeile, $zeilenNummer)
            # $max_spc = 45

    #write-host -b darkyellow -f white ("[$zeile] --- [$($zeile.length)]" )

            # $item += (" "*$max_spc)
            # $endspc = (($params | sort {$_.length} | % {$_.length})[-1]) +1 - ($item.length) 
            write-host -non -f Green ("`n {0,3} " -f $zeilenNummer ) # ++$i)
            write-host -non -f darkGray ("[" )
            write-host -non -b Cyan -f Black (" {0}" -f "$($zeile)$($spaces)".Substring(0,$max_spc) ) 
            #write-host -non -b Cyan -f Black (" {0}" -f $zeile.Substring(0,$max_spc) ) 
            Write-Host -f DarkGray ("]")  
        }

            if($exit.length -gt 0){ ZeilenMenuAufbauen -zeile $exit_fuer_menu -zeilenNummer $i $max_spc}

        foreach ($item in $Text_fuer_Menuzeilen)
        {
            ++$i
            ZeilenMenuAufbauen -zeile "$item" -zeilenNummer $i
        }
    }
    
    
    # Fortlaufende Nummerierung  fuer den Save-Ordner generieren
    function create-folder-mit-fortlaufender-Nummer {
        param(
            [string]$savePath
        )
            if (Test-Path "$($savepath)*")
            { 
                $tmpg =  Get-ChildItem  "$($savepath)*"   `
                         | ? { $_.BaseName -match "([0-9]+)$"} `
                         | % {[int]$Matches[1]} | sort | select -Last 1
                 
                $savepath +=  if ($tmpg.count -eq 0) {1}else{ $tmpg  +1}

            } 
            	
            new-item -Path $savepath -ItemType Directory -ErrorAction SilentlyContinue -Verbose | Out-Null

            return $savePath

        # Testausgabe:
        #    $savepath
    }

    # Fortlaufende Nummerierung  fuer den Save-Ordner generieren
    function get-folder-mit-fortlaufender-Nummer {
        # file system refresh to slow? if now created a folder 'fixed3' and this function found old 'fixed2'
        param( [string]$Path )

        if (Test-Path "$($Path)*")
        { 
            $Path =  Get-ChildItem  "$($Path)*"   `
                        | Where-Object { $_.BaseName -match "([0-9]+)$"} `
                        | sort {[int]$Matches[1]} `
                        | select -Last 1
            return $Path
        } 
    }

#endregion

# START:
Main  -Verbose



Edit, 22.Januar.2025
i have the batch-file modified, old:

Code: Select all

                    $tmp = $tmp -replace '(?<=!\[.*?\]\()(?<Path>.*?)(?=[^\/\\]*?\))', $imagePath
new:

Code: Select all

                    # ---- $tmp = $tmp -replace '(?<=!\[.*?\]\()(?<Path>.*?)(?=[^\/\\]*?\))', $imagePath
                    $patt = '(?<=!?\[.*?\]\()(?<Path>[a-z]:.*?)(?=[^\/\\]*?\))'
                    $tmp = $tmp -replace $patt , $imagePath

Re: Broken images in Markdown viewer

Posted: 02 Feb 2025, 00:24
by AD7
powerlicht wrote: 20 Jan 2025, 18:27 I couldn't get the relative path to work either.
...

I see you use a AS v5.0.
Where it is from? Some news inside, against v4.0?

Thanks.

Re: Broken images in Markdown viewer

Posted: 02 Feb 2025, 08:18
by pjj
AD7 wrote: 02 Feb 2025, 00:24 I see you use a AS v5.0.
Where it is from? Some news inside, against v4.0?
Link was posted just yesterday. I wish it was more prominent, too.

I don't know what exactly has been added, but WebP preview works fantastic!

Re: Broken images in Markdown viewer

Posted: 02 Feb 2025, 13:45
by AD7
pjj wrote: 02 Feb 2025, 08:18
AD7 wrote: 02 Feb 2025, 00:24 I see you use a AS v5.0.
Where it is from? Some news inside, against v4.0?
Link was posted just yesterday. I wish it was more prominent, too.

I don't know what exactly has been added, but WebP preview works fantastic!
Thanks, I thought there was another one somewhere. :D

Quick compare of Plugins folder AS 4 vs AS 5:

Re: Broken images in Markdown viewer

Posted: 02 Feb 2025, 22:27
by powerlicht
AD7 wrote: 02 Feb 2025, 00:24 I see you use a AS v5.0.
Where it is from? Some news inside, against v4.0?

Thanks.
i have download OpenSalamander v5.0 from a fork (Dec 30, 2024):
https://github.com/OFreddy/salamander