vsch / idea-multimarkdown

Markdown language support for IntelliJ IDEA.
https://plugins.jetbrains.com/plugin/7896-markdown-navigator
Apache License 2.0
815 stars 127 forks source link

Can't disable 'Add query suffix to URI which increments when file changes' option #729

Closed Jelmerb closed 5 years ago

Jelmerb commented 5 years ago

IDE: IntelliJ IDEA Ultimate 2018.3.5 Markdown Navigator 2.8.2.58

When I add a custom CSS stylesheet in the 'Apply CSS from URI' and I export my markdown to HTML the CSS file gets a weird filename (github-markdown.css%3F0). As expected it isn't applied to the exported HTML (although the weird file name is used in the HTML head). So my solution was to disable the option mentioned in the title, only it doesn't get disabled. It just enables again after I leave the settings.

Stylesheet settings

After exporting the HTML I get this message: /Users/jelmerbrands/Development/md/sead.wiki/export/css/github-markdown.css%3F0: copied /css/github-markdown.css?0: /css/github-markdown.css?0 (No such file or directory)

These might be two separate issues. If I have to report a separate issue to help you keep everything in order, just let me know.

vsch commented 5 years ago

@Jelmerb, the trailing ?0 is caused by the Add query suffix to URI... option. In the fix for copying the CSS I forgot to add stripping out of the query from the URL when generating the file name for copying.

What do you mean by disable the option mentioned in the title? Is it the Override Project Settings or Apply CSS from URI?

vsch commented 5 years ago

@Jelmerb, re-read the title and got my answer. Did not understand that by title you meant title of the issue.

Jelmerb commented 5 years ago

My bad, I was not clear enough.

vsch commented 5 years ago

@Jelmerb, not your fault. When I read the issue, the water for my coffee was still heating up.

The issue is caused by omission of the use query suffix from the settings equal/hashcode so when you change only this checkbox the change is not detected.

This code got a bit of chewing up when I added all these options to the basic version. One of the main reasons why I was hesitant to do it because it caused a lot of churn in the UI.

I will make an EAP release for both fixes.

vsch commented 5 years ago

EAP update with a fix for the issue is available.

Installing EAP Plugin Version

Jelmerb commented 5 years ago

I downloaded the new version: 2.8.2.60

I disabled 'Add query suffix to URI which increments when file changes'. The setting change is now persisted but exporting to HTML stopped working altogether and throws the following exception (original file is github-markdown.css):

java.io.FileNotFoundException: /css/github-markdown.css?0 (No such file or directory) at java.io.FileInputStream.open0(Native Method) at java.io.FileInputStream.open(FileInputStream.java:195) at java.io.FileInputStream.(FileInputStream.java:138) at kotlin.io.FilesKt__FileReadWriteKt.readBytes(FileReadWrite.kt:63) at com.vladsch.idea.multimarkdown.util.HtmlExporter.computeOtherFileMapping(HtmlExporter.kt:369) at com.vladsch.idea.multimarkdown.util.HtmlExporter$exportAllHtml$3$1$1.invoke(HtmlExporter.kt:625) at com.vladsch.idea.multimarkdown.util.HtmlExporter$exportAllHtml$3$1$1.invoke(HtmlExporter.kt:72) at com.vladsch.plugin.util.ui.SteppedProgressIndicator.nextGradation(SteppedProgressIndicator.kt:60) at com.vladsch.plugin.util.ui.SteppedProgressIndicator.nextGradation$default(SteppedProgressIndicator.kt:55) at com.vladsch.idea.multimarkdown.util.HtmlExporter$exportAllHtml$3$1.run(HtmlExporter.kt:625) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:948) at com.vladsch.idea.multimarkdown.util.HtmlExporter$exportAllHtml$3.invoke(HtmlExporter.kt:624) at com.vladsch.idea.multimarkdown.util.HtmlExporter$exportAllHtml$3.invoke(HtmlExporter.kt:72) at com.vladsch.plugin.util.ui.SteppedProgressIndicator.nextRegion(SteppedProgressIndicator.kt:84) at com.vladsch.idea.multimarkdown.util.HtmlExporter.exportAllHtml(HtmlExporter.kt:623) at com.vladsch.idea.multimarkdown.MdProjectComponent$exportAllHtmlRaw$1.run(MdProjectComponent.kt:1180) at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:727) at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:164) at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:582) at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:532) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:87) at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:151) at com.intellij.openapi.progress.impl.CoreProgressManager$4.run(CoreProgressManager.java:403) at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:314) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

vsch commented 5 years ago

@Jelmerb, in a rush to fix the destination file name I forgot to do the same query stripping on the source file URI.

vsch commented 5 years ago

@Jelmerb, I took the time to add a test case for query string export to make sure it does work.

EAP update with a fix for the issue is available.

Installing EAP Plugin Version

Jelmerb commented 5 years ago

@vsch Thanks for your hard work.

The custom CSS file gets copied correctly if I enter the complete path to a file in the URI field. If I enter an invalid URI, I still get an exception. I think it would be better to warn the user beforehand if the URI is invalid. Wouldn't it be better if the user could just select a file on the filesystem? I had no idea what the URI should look like, I just tried the full path after the relative path failed.

vsch commented 5 years ago

@Jelmerb, I agree. I have not reviewed this feature since its early implementation. I will add a browse button and error checking to make sure the URI is valid and convert it to absolute path if a relative path is given.

vsch commented 5 years ago

@Jelmerb, added browse button, validation and error message if URI is file URI and file does not exists or URI is missing protocol prefix. Also generating error in export log message if CSS URI does not exist.

EAP update with a fix for the issue is available.

Installing EAP Plugin Version

Jelmerb commented 5 years ago

Nice, it works now. The preview also has the custom CSS applied which wasn't the case before. Nice job 🙂.

vsch commented 5 years ago

@Jelmerb, the preview always used the provided CSS URI but if it was not valid the preview browser would ignore it. Having validation helps identify problems in configuration.

This code has not seen much attention in a while. I have learned a lot about the JetBrains API since I wrote it but did not give it much attention since.

I am glad you raised this issue. It motivated some overdue cleanup and updating.

Jelmerb commented 5 years ago

No problem, happy to help.