-
-
Save ErwanLeroux/ae7a7083e16f31995b69 to your computer and use it in GitHub Desktop.
Example script that will convert Github Flavoured Markdown text into HTML (using Github's API).
This file contains hidden or 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
#!/usr/bin/env php | |
/* | |
Permalink : https://gist.github.com/ErwanLeroux/ae7a7083e16f31995b69 | |
Forked from https://gist.github.com/cobusc/8707593/1cf6eb7b932890a8bcddf927c95091154bede377 | |
*/ | |
<?php | |
$RENDER_URL = "https://api.github.com/markdown"; | |
$INPUT = $argv[1]; | |
$OUTPUT = $argv[2]; | |
$payload["text"] = file_get_contents($INPUT); | |
$payload["mode"] = "markdown"; | |
$payload["context"] = ""; | |
$ch = curl_init($RENDER_URL); | |
$fp = fopen($OUTPUT, "w"); | |
//TODO supprimer l'extension du fichier dans la balise titre | |
fwrite($fp, ' | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=\'utf-8\'> | |
<title>Shaarli - '.basename($INPUT).'</title> | |
<style type="text/css">code{white-space: pre;}</style> | |
<!--[if lt IE 9]> | |
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
<link rel="stylesheet" href="github-markdown.css"> | |
</head> | |
<body> | |
<h1 id="'.basename($INPUT).'">'.basename($INPUT).'</h1> | |
'); | |
$options = array( | |
CURLOPT_URL => $RENDER_URL, | |
CURLOPT_CUSTOMREQUEST => "POST", | |
CURLOPT_POSTFIELDS => json_encode($payload), | |
CURLOPT_FILE => $fp, | |
CURLOPT_USERAGENT => "ErwanLeroux" | |
); | |
curl_setopt_array($ch,$options); | |
curl_exec($ch); | |
curl_close($ch); | |
fwrite($fp,' | |
</body> | |
</html>'); | |
fclose($fp); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PHP Fatal error: Call to undefined function curl_init() resolved by installing php5-curl