Last active
December 12, 2016 19:50
-
-
Save KEINOS/11da51d82b44640fa4c391294a5a7bbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* ======================================================================= | |
Markdown記法(.md)ファイルをHTML記法に変換するスクリプト | |
拡張子.mdの場合、このファイルを開くようにhtaccessで定義。環境変数($_SERVER)情報より | |
該当mdファイルを参照し、Parsedownクラスを使ってHTML形式に変換を行う。 | |
・ Parsedown : http://parsedown.org/ | |
・ 詳細 : https://blog.keinos.com/20161213_1906 | |
・ 参照元 : http://blog.fenrir-inc.com/jp/2012/05/github_markdown.html | |
======================================================================= */ | |
require_once '/path/to/parsedown.php'; | |
if ( isset( $_SERVER['PATH_TRANSLATED'] ) ) { | |
$file = realpath( $_SERVER['PATH_TRANSLATED'] ); | |
$ext = substr( $file, strrpos( $file, '.' ) + 1 ); | |
} | |
if ( $file and is_readable( $file ) and $ext === 'md' ){ | |
$oParsedown = new Parsedown(); | |
$sBody = $oParsedown->text( file_get_contents( $file ) ); | |
} else { | |
$sBody = '<p>cannot read file</p>'; | |
} | |
header('Content-Type: text/html;'); | |
?> | |
<html> | |
<head> | |
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /> | |
<title><?php echo "{$file}"; ?></title> | |
<link rel="stylesheet" type="text/css" href="//path/to/your/reset.css"> | |
</head> | |
<body><?php echo $sBody; ?></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment