Bosse_B
Posts: 966
Joined: Thu Jan 30, 2014 9:53 am

Can apache on rpi4 serve markdown documents?

Mon Mar 30, 2020 8:27 am

I have kept notes in a txt file on my computer on various Linux issues I have encountered when working on RPi projects.
Now I have converted it to a markdown document (extension md) in order to make it easier to navigate and read.

It works fine in Windows 10 when I drop it onto my Firefox browser (where I have installed the Markdown Viewer web extension)..

But when I copied the file to my RPi4 into the web dir and try to access it via the browser using http:// syntax it does not show up.
Instead I am getting a dialog asking me if I want to save the file or send it to a different application.

Quite a disappointment after spending many hours on the conversion...

Is there some way to configure apache such that it will in fact serve the markdown file as a document displayed in any browser?
Here is the Firefox dialog at the moment:

FirefoxMDdialog.png
FirefoxMDdialog.png (9.88 KiB) Viewed 293 times
Bo Berglund
Sweden

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Can apache on rpi4 serve markdown documents?

Mon Mar 30, 2020 2:28 pm

Yes it can. The issue seems to be how Firefox treats local files (.md) on the PC to those from a webserver (pi3 running apache2).
I installed Markdown Viewer Webext Add-On into Firefox on my PC.
Open a local File "README.md" (python requests library documentation) on the PC using Firefox on that PC - all OK
Try to open the same file being served from a raspberry pi running apache2 - firefox asks to open/save the file.
A workaround for now is:
So, tell firefox to save the file, then go to Options. Scroll down to Applications - you will now see "MD file" set to "Always Ask"
Open the file again from pi running apache2 - firefox asks to open/save the file - this time set it toOpen with Firefox, and do this automatically from now on.
There must be a better way?

Bosse_B
Posts: 966
Joined: Thu Jan 30, 2014 9:53 am

Re: Can apache on rpi4 serve markdown documents?

Mon Mar 30, 2020 3:34 pm

Yeah, this is basically what I have seen too.
A local file system MD file renders OK (through the add-on) but not when served by apache2.
I got to a state where Firefox will save the file to a local temp dir and then display it from there (if I set "open with" to Firefox).
But then it is still a local file being displayed (as seen in the address bar).
Last iteration I did placed the file here:
file:///C:/Users/Bosse/AppData/Local/Temp/LinuxCommands-3.md

If I use Chrome I get to see the raw file without any MD rendering at all...
Bo Berglund
Sweden

User avatar
DougieLawson
Posts: 38882
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Can apache on rpi4 serve markdown documents?

Mon Mar 30, 2020 6:46 pm

Do you mean serve or render?
Have you set the right MIME-type?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
dickon
Posts: 1451
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: Can apache on rpi4 serve markdown documents?

Mon Mar 30, 2020 6:52 pm

It looks like there's a mod_perl2 handler -- a trivial google will find it -- which will render the thing before sending it to the browser, which should do what you want for reading. Otherwise, try a Wiki engine: most of them use a variant of it.

Bosse_B
Posts: 966
Joined: Thu Jan 30, 2014 9:53 am

Re: Can apache on rpi4 serve markdown documents?

Mon Mar 30, 2020 8:19 pm

DougieLawson wrote:
Mon Mar 30, 2020 6:46 pm
Do you mean serve or render?
Have you set the right MIME-type?
Well, what I mean is:
- I put the file LinuxCommands.md into a web dir on the server
- I use the browser and open URL http://myserver.com/doc/LinuxCommands.md
- The document is shown as an MD document fully rendered in my browser (not working now)

Right now using Firefox and the add-on for markdown this local URL will properly display the document:
file:///D:/RaspberryPi/LinuxCommands.md

If this is serve or render I don't know, what is the difference?
I would like to access the document via the server so it is available in most situations.
I have a dynamic domain pointing to my apache2 server.
Bo Berglund
Sweden

Bosse_B
Posts: 966
Joined: Thu Jan 30, 2014 9:53 am

Re: Can apache on rpi4 serve markdown documents?

Mon Mar 30, 2020 8:20 pm

dickon wrote:
Mon Mar 30, 2020 6:52 pm
It looks like there's a mod_perl2 handler -- a trivial google will find it -- which will render the thing before sending it to the browser, which should do what you want for reading. Otherwise, try a Wiki engine: most of them use a variant of it.
Hmm,
why mod_perl2?
Should it not be mod_markdown or similar?
I am not using perl anywhere I know.
Bo Berglund
Sweden

User avatar
DougieLawson
Posts: 38882
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Can apache on rpi4 serve markdown documents?

Mon Mar 30, 2020 8:21 pm

That's rendering.

https://github.com/hamano/apache-mod-markdown (don't know if that will compile and install OK on Raspbian, you'll need a whole lot of Apache2 development tools and libraries).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
neilgl
Posts: 2111
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Can apache on rpi4 serve markdown documents?

Mon Mar 30, 2020 9:51 pm

The workaround is ok for now

User avatar
dickon
Posts: 1451
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: Can apache on rpi4 serve markdown documents?

Mon Mar 30, 2020 10:23 pm

Bosse_B wrote:
Mon Mar 30, 2020 8:20 pm
dickon wrote:
Mon Mar 30, 2020 6:52 pm
It looks like there's a mod_perl2 handler -- a trivial google will find it -- which will render the thing before sending it to the browser, which should do what you want for reading. Otherwise, try a Wiki engine: most of them use a variant of it.
Hmm,
why mod_perl2?
Should it not be mod_markdown or similar?
I am not using perl anywhere I know.
Just something I spotted whilst looking at the problem. mod_perl2 is a *very* useful Apache module I happen to have used a fair bit, and it's the sort of thing I'd expect to be able to do this sort of thing without difficulty.

Return to “General discussion”