NppMarkdownPanel icon indicating copy to clipboard operation
NppMarkdownPanel copied to clipboard

Display images with a space character in the filename — %20

Open AlttiRi opened this issue 4 years ago • 1 comments

It should display a local image that has a space character in the filename if the image is included with escaping (%20).

For example, I have an image 123 4.png.

I include it to .md file with: ![](123%203.png "").

It works fine, for example, both in GitHub and in IntelliJ IDEA. But this plugin does not work with this case.

AlttiRi avatar Mar 27 '21 20:03 AlttiRi

UPD. Not only a space character, but other chars too (which should be encoded). For example, if I have [image] example 1—1.png then I should include it as %5Bimage%5D%20example%201%E2%80%941.png.

AlttiRi avatar Mar 27 '21 21:03 AlttiRi

This is a bug under IE/Edge with local file links containing non US-ASCII chars, with escape chars in URL with %..

Can this be inserted in MarkdownPreviewForm.cs in line 128?

            //Unescape local file links containing non US - ASCII chars because of IE/Edge bug
            //But unescape all is probably too much...
            resultForBrowser = Uri.UnescapeDataString(resultForBrowser);

Tests in Zip: test nonAscii path.zip

andrzejQ avatar Jan 10 '23 19:01 andrzejQ

        public static MarkdownPipelineBuilder UseNonAsciiNoEscape(this MarkdownPipelineBuilder pipeline);
        //     Uses this extension to disable URI escape with % characters for non-US-ASCII
        //     characters in order to workaround a bug under IE/Edge with local file links containing
        //     non US-ASCII chars. DO NOT USE OTHERWISE.

but inserting it in MarkdigMarkdownGenerator.cs doesn't work:

        public string ConvertToHtml(string markDownText, string filepath)
        {
...
            var pipeline = new MarkdownPipelineBuilder()

                .UseNonAsciiNoEscape()

andrzejQ avatar Jan 11 '23 07:01 andrzejQ

This is a bug under IE/Edge with local file links containing non US-ASCII chars, with escape chars in URL with %..

Can this be inserted in MarkdownPreviewForm.cs in line 128?

            //Unescape local file links containing non US - ASCII chars because of IE/Edge bug
            //But unescape all is probably too much...
            resultForBrowser = Uri.UnescapeDataString(resultForBrowser);

I think its no good idea to unescape the complete document. This can lead to undesired side effects. It would be better to unescape only src attribute of img tags.

mohzy83 avatar Jan 11 '23 09:01 mohzy83

        public static MarkdownPipelineBuilder UseNonAsciiNoEscape(this MarkdownPipelineBuilder pipeline);
        //     Uses this extension to disable URI escape with % characters for non-US-ASCII
        //     characters in order to workaround a bug under IE/Edge with local file links containing
        //     non US-ASCII chars. DO NOT USE OTHERWISE.

but inserting it in MarkdigMarkdownGenerator.cs doesn't work:

        public string ConvertToHtml(string markDownText, string filepath)
        {
...
            var pipeline = new MarkdownPipelineBuilder()

                .UseNonAsciiNoEscape()

Doesn't work for me neither. Actually this setting should produce the desired result.

mohzy83 avatar Jan 11 '23 09:01 mohzy83

This can be inserted in MarkdownPreviewForm.cs in line 128 (desperate solution). (I have created pull request).

            //using System.Text.RegularExpressions;
            //string inp = " * %25%20x : `<img src=\"file:///C:/tmp/test%20nonAscii%20path/A%C4%85C%C4%87E/A%C4%84%2520(2).png\" />`";
            //outp:          * %25%20x : `<img src="file:///C:/tmp/test nonAscii path/AąCćE/AĄ%20(2).png" />`
            Regex regex = new Regex("src=\"file:///[^\"]+");
            resultForBrowser = regex.Replace(resultForBrowser, m => Uri.UnescapeDataString(m.Value));

nppMdP.tests.zip

andrzejQ avatar Jan 11 '23 19:01 andrzejQ

fixed in release 0.7.2

mohzy83 avatar Feb 11 '23 10:02 mohzy83