Parsedown Render V2
postsHere is version two of the parsedown based general .md file viewer
This time I added support for Math Jax, which will make it easier for me to post documents marked in LaTeX and ASCIIMaths. Which is very useful! Especially for future collaboration or documentation efforts.
<?php
/*
Project: parsedown Render
Coder: Brian Khuu briankhuu.com
VERSION: v2.0 (MathJax and raw view support now)
Purpose: To allow for displaying of .md file transparently to visitors via http://parsedown.org and mod_rewrite
Usage: Place this file (parsedownRender.php) in your root directory and add these lines below to your .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)\.md [NC]
RewriteRule . /parsedownRender.php?file=%{REQUEST_URI}&%{QUERY_STRING} [L]
</IfModule>
*/
$file = "./".$_GET["file"]; // 'file' => /md/test.md
$css = isset($_GET['css']) ? htmlspecialchars($_GET['css']) : "http://kevinburke.bitbucket.org/markdowncss/markdown.css";
$viewMode = isset($_GET['view']) ? htmlspecialchars($_GET['view']) : "";
if ( $viewMode == "raw"){ echo file_get_contents($file); exit(); }
function parsedownInclude($f){
require_once 'Parsedown.php';
$Parsedown = new Parsedown();
echo is_readable($f) ? $Parsedown->text(file_get_contents($f)) : "File Not Found: ".htmlspecialchars($f);
}
?>
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="<?php echo $css ?>" />
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_HTMLorMML"></script>
</head>
<body>
<?php parsedownInclude($file); echo "<hr><a href='?view=raw'>VIEW RAW</a>"; ?>
</body>
</html>