simov / markdown-viewer

Markdown Viewer / Browser Extension
MIT License
1.01k stars 131 forks source link

How to view file #202

Closed PaltryProgrammer closed 1 year ago

PaltryProgrammer commented 1 year ago

MD Viewer is a complete mystery to me . Please see attached GIF . i am merely attempting to view a page i assume is MD . i performed the copy and paste of the address as i believe is required as can be seen but still page does not display as MD . may i say a less user friendly program i have not ever seen . all a user should do it seems to me is load the page and MD Viewer does the rest at a click of a button if necessary e.g. upon loading a page click on MD icon . then click on "view current page in MD format" . Voila Bingo Presto that should be enough . apparently displaying MD format is akin to flying the Space Shuttle . perhaps the page is not MD in which case MD Viewer can inform user of same . How to View Page in MD Format

simov commented 1 year ago

Yes, the content that you are trying to render is XML, not Markdown, so it won't work because of that alone. Then also each origin has a path matching regex that you can edit after you enable the origin, devblogs.microsoft.com in your case and click on it to expand it, but again, that's not relevant in your case since the content that you are looking at is not Markdown to begin with.

As for the error messaging, I do agree that maybe something can be improved in that direction, and I can assure you that I have spent a lot of time thinking about how can I make this extension as user friendly as possible.

As a general rule of thumb, not every web site serves raw markdown content.You can take the examples section of the documentation, try to enable each one of those origins and play around with the extension - that is a Markdown content. For any other web site that you are unsure of you can open up the devtools and check the content-type header of the request serving the page document. Try with the page from your GIF above.

PaltryProgrammer commented 1 year ago

Thank You for your Kind and informative reply . Please permit me to offer my own thoughts re/ methods MD Viewer can perform in a user friendly manner. It seems to me it perhaps can be done as follows :

In conclusion i must assume MD display is somehow different from HTML display as you are no doubt a much better and more knowledgeable programmer than myself but i offer these paltry thoughts none the less -Best -Kind Regards PS re/ suggestion checking content-type header it is my ignorant opinion MD Viewer can do it for me automatically

simov commented 1 year ago

The extension is already checking for the existence of a valid content-type header, you can read about it here. If you have allowed the extension on All Origins in the Advanced Options page, and the header detection is on, which it is by default, then regardless of the URL path format in the address bar, if the remote server served the content with a markdown content-type then the extension will try to render it.

The problem arises when a page serves a valid Markdown content but without the appropriate content-type value. In that case the so called Path Matching RegExp for each origin can be used to determine if the page should be considered for rendering as a Markdown. Which on its own creates yet another problem - a page address that matches your regular expression, but it is not a Markdown content. In that case you have to tweak the default Path Matching RegExp.

Every application is using the content-type header to determine the type of the content being served, including the web browser. That is the reason why the browser renders HTML, but not Markdown, because it determines that it is a Markdown content by reading the content-type header, and it doesn't know how to render it.

Parsing the document upfront to determine if a page that did not send the correct content-type header is a valid markdown or not can be very unreliable.

simov commented 1 year ago

Have a look at your other ticket https://github.com/simov/markdown-viewer/issues/206 for more details. In the latest v5.1 version of the extension the content detection algorithm was greatly improved. Thanks for the feedback again.