Bosse_B
Posts: 1084
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 763 times
Bo Berglund
Sweden

User avatar
neilgl
Posts: 2662
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

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: 1084
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: 40789
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?
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

User avatar
dickon
Posts: 1886
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.
As it is apparently board policy to disallow any criticism of anything, as it appears to criticise something is to criticise all the users of that something, I will no longer be commenting in threads which are not directly relevant to my uses of the Pi.

Bosse_B
Posts: 1084
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: 1084
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: 40789
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).
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

User avatar
neilgl
Posts: 2662
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

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: 1886
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.
As it is apparently board policy to disallow any criticism of anything, as it appears to criticise something is to criticise all the users of that something, I will no longer be commenting in threads which are not directly relevant to my uses of the Pi.

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

Re: Can apache on rpi4 serve markdown documents?

Sat Nov 21, 2020 10:07 am

Revitalizing this thread again since I am now overwhelmed with a lot of new md files where I keep notes/instructions/howtos on my laptop.
I can open them in Firefox using URL:s pointing to the local file system.
It works reasonably with the MD plug-in to Firefox, but it is a PITA to have to add file system URL:s to the bookmarks in Firefox.

And it is inconvenient too since it results in broken links if I should want to see the instructions on say my phone or another device (which sync the Firefox bookmarks but have no access to local files on my laptop).

Is there really no ready-made solution to enable the rendering of MD documents server side (Apache) before sending them to the client as html?
If so then I could put all of these handy documents on my RPi4, which is available (to me after a logon) on the Internet and thus to my phone web browser too.

I cannot code anything server side for Apache so unless there is a ready-made solution I am toast.
A cook-book instruction on how to fix up Apache is what is needed, I believe.

Any advice on this is greatly appreciated!
Bo Berglund
Sweden

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

Re: Can apache on rpi4 serve markdown documents?

Sat Nov 21, 2020 10:23 am

Bosse_B wrote:
Sat Nov 21, 2020 10:07 am
Is there really no ready-made solution to enable the rendering of MD documents server side (Apache) before sending them to the client as html?
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.
DougieLawson wrote:
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).
As it is apparently board policy to disallow any criticism of anything, as it appears to criticise something is to criticise all the users of that something, I will no longer be commenting in threads which are not directly relevant to my uses of the Pi.

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

Re: Can apache on rpi4 serve markdown documents?

Sat Nov 21, 2020 12:50 pm

dickon wrote:
Sat Nov 21, 2020 10:23 am
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.
By what I can see mod_perl2 is a module that makes Apache understand Perl....
And BTW, searching for "mod_perl2 handler" did not turn up any perl2 hits at all, but lots of mod_perl pages.
What is mod_perl2?

But Perl is not what I asked about, I wanted to know how to make Apache understand how to render markdown documents...
We use VisualSVN at work and whenever there is an md file it will show up properly when we visit the VisualSVN site in any browser.
That functionality for showing the content is what I am after, and by the number of dead-end google hits I have found I am not really alone here...

But I am not able to write a handler myself, especially not using Perl.
Bo Berglund
Sweden

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

Re: Can apache on rpi4 serve markdown documents?

Sat Nov 21, 2020 3:26 pm

Bosse_B wrote:
Sat Nov 21, 2020 12:50 pm
By what I can see mod_perl2 is a module that makes Apache understand Perl....
And BTW, searching for "mod_perl2 handler" did not turn up any perl2 hits at all, but lots of mod_perl pages.
What is mod_perl2?
mod_perl(2) is an Apache module which embeds a Perl interpreter into the Apache binary, and exposes Apache's internal API to Perl scripts which run inside it. Because of its architecture, it's a lot quicker than forking Perl each time as a CGI, and it has the ability to filter Apache's input and output at various points of a object's server lifecycle.
Bosse_B wrote:
Sat Nov 21, 2020 12:50 pm
But Perl is not what I asked about, I wanted to know how to make Apache understand how to render markdown documents...
There are many, many free scripts that will run on it, and only need installing and configuring. https://metacpan.org/pod/Text::Markdown::ApacheHandler took me all of several seconds to locate, for example. Nobody is suggesting you code anything. None of this is rocket science.
As it is apparently board policy to disallow any criticism of anything, as it appears to criticise something is to criticise all the users of that something, I will no longer be commenting in threads which are not directly relevant to my uses of the Pi.

MikeCross
Posts: 56
Joined: Wed Mar 06, 2013 6:21 pm

Re: Can apache on rpi4 serve markdown documents?

Sat Nov 21, 2020 6:23 pm

Re: Can apache on rpi4 serve markdown documents?
Yes, it can, and does, out of the box. It will serve many kinds of documents. The converting of a document into human-readable form, 'rendering', usually happens in the browser (unless the file has content that needs to be processed by the server, eg PHP code).

An HTML page is served to the browser by the web server, but it's the browser that converts the HTML into formatted text; browsers automatically understand, and know how to render, HTML.

So, for the md file to be displayed correctly in the browser, the browser needs to understand Markdown, or the web server needs to process the file with a handler, as discussed up-thread, and then send the formatted content to the browser.

I saved an md file (MP3_Player.md) to my Pi4, copied it to /var/www, and loaded the file in Chrome on my PC (http:/Pi4 IP Address/MP3_Player.md)- it displayed the Markdown source. I installed the Markdown Viewer extension into Chrome from the Google Store, configured it to access files, and refreshed the tab where the md file was displayed... Chrome now displayed the formatted md file!

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

Re: Can apache on rpi4 serve markdown documents?

Sat Nov 21, 2020 10:52 pm

I was advised by my son-in-law to have a look at this stack overflow thread and lo-and-behold there was a stepwise instruction on how to create and install a markdown module in apache2!
Have a look at the answer in this thread....

I replicated the instructions as well as I understand them but unfortunately I seem to get only partially to the solution.
The page is now sent to the browser as a rendered page but it does not really work, seems to only be partially rendered...

Probably the apache-mod-markdown code on GitHub is too old? How can one see the server age of the files one checks out?
It does not render links within the document so they work, which they do if I do a client side render using an add-on for FireFox.
Bo Berglund
Sweden

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

Re: Can apache on rpi4 serve markdown documents?

Sat Nov 21, 2020 11:24 pm

So you hadn't even bothered looking at DougieLawson's suggestion, then.

Great.
As it is apparently board policy to disallow any criticism of anything, as it appears to criticise something is to criticise all the users of that something, I will no longer be commenting in threads which are not directly relevant to my uses of the Pi.

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

Re: Can apache on rpi4 serve markdown documents?

Sat Nov 21, 2020 11:44 pm

dickon wrote:
Sat Nov 21, 2020 11:24 pm
So you hadn't even bothered looking at DougieLawson's suggestion, then.
Yes, I had.
But the instructions on github were not full so I did not know how to go about it.
With the Stack Overflow answer the way to install it became clear.
Incomplete suggestion, at least for a dummie like me...
Bo Berglund
Sweden

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

Re: Can apache on rpi4 serve markdown documents?

Sun Nov 22, 2020 11:58 am

I got it working now except for the style sheet, which I downloaded from github separately.

The problem is that I have a lot of RPi code samples in my md documents and these are written within backtick markers ( ``` ) like this example:

Code: Select all

Alt 2: Edit files manually (works on all Linux machines):  
```
sudo nano /etc/hostname  (change single line to new hostname)
sudo nano /etc/hosts     (change entry for 127.0.1.1)
sudo /etc/init.d/hostname.sh
sudo reboot
```  
When I open this in FireFox directly from the file system I get proper code display with each command on separate lines.
But in the display via Apache this does not happen.
Top is with the Apache rendering, bottom is the same file viewed directly from the file system and rendered by the FireFox plug-in:

markdown.png
markdown.png (14.96 KiB) Viewed 160 times
What can I do to reach the view style at the bottom?
The css style sheet used is attached in the zip.
Attachments
markdown.zip
(2.03 KiB) Downloaded 5 times
Bo Berglund
Sweden

Return to “General discussion”