A PHP Markdown script with syntax highlighting. This script allows Apache to convert md files into HTML.
Find a file
2019-05-13 18:58:14 +02:00
hcode.css Initial code commit 2019-05-13 17:24:11 +02:00
hcode.js Initial code commit 2019-05-13 17:24:11 +02:00
index.html Removed broken link in website 2019-05-13 18:36:12 +02:00
LICENSE Initial commit 2019-05-13 17:19:16 +02:00
LISEZMOI.md Update LISEZMOI.md 2019-05-13 18:48:52 +02:00
md.php Initial code commit 2019-05-13 17:24:11 +02:00
README.md Update README.md 2019-05-13 18:58:14 +02:00
w3.css Initial code commit 2019-05-13 17:24:11 +02:00

md.php Script

GitHub version
This PHP script aims to render MarkDown (.md) files using Apache and PHP. As long as the script is installed, you can request .md files from your browser, and see them correctly formatted in HTML. For instance : http://www.mywebsite.com/README.md will be displayed in HTML instead of full text.

Installation

Download this script on GitHub.com. Just copy the md.php, w3.css, hcode.css and hcode.js files to the root of the site. Documentation is available on project's website.

Configuration

To use this script, add the following lines to the httpd.conf file in the Virtual Host section:

RewriteEngine on
RewriteRule (.*)\.md$ /md.php?f=$1

Example :

This example shows a localweb configucation complete with URL rewriting enabled for .md files.

## Virtualhost localweb
<VirtualHost 192.168.1.x>
	DocumentRoot "C:/Work/PHP"
	ServerName 192.168.1.x
	
	RewriteEngine on
	RewriteRule (.*)\.md$ /md.php?f=$1
	
	<Directory "C:/Work/PHP">
		Options FollowSymLinks Indexes ExecCGI
		AllowOverride All
		Order allow,deny
		Allow from all
		Require all granted
	</Directory>
</VirtualHost>

For more information on the Rewriting URL with Apache, see : Apache WebSite.

Using with PHP

You can also use md.php in your PHP scripts to get the HTML rendering of a character string. First of all, you need to include in the head section of the HTML document the following lines:

<head>
	<link rel="stylesheet" href="/w3.css">
	<link rel="stylesheet" href="/hcode.css">
	<script src="/hcode.js"></script>
	<script>hljs.initHighlightingOnLoad();</script>
</head>

Then, just use the script as follows:

require_once "md.php";
$Markdown = new Markdown();
$htmlMarkDown = $Markdown->text("Hello, this is a **MarkDown** string.");
echo($htmlMarkDown);

References

This script is based on the following scripts:

Check these sites for more information on how md.php works.