All scripts in one repository

This commit is contained in:
mmk2410 2015-11-12 22:36:23 +01:00
parent a0a86492ee
commit 9f9304d6aa
61 changed files with 6668 additions and 681 deletions

22
md2html/LICENSE Normal file
View file

@ -0,0 +1,22 @@
COPYRIGHT (c) 2015 mmk2410
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

13
md2html/Makefile Normal file
View file

@ -0,0 +1,13 @@
all:
install:
mkdir -p /opt/md2html/
mkdir -p /opt/md2html/libs/
mkdir -p /opt/md2html/src/
install libs/* /opt/md2html/libs/
install src/* /opt/md2html/src/
install md2html.php /usr/bin/md2html
remove:
rm -rf /opt/md2html
rm /usr/bin/md2html

30
md2html/README.md Normal file
View file

@ -0,0 +1,30 @@
# md2html
md2html is a simple script that converts markdown files to html code and optionally saves it into a .txt or .html file. The library that powers the whole thing is [Parsedown](https://github.com/erusev/parsedown).
## Installation
To use this script, install `php` and run the following command:
```
sudo make install
```
**You have to add /opt/md2html to your php.ini open_basedir !**
## Usage
Print the help:
```
md2html --help
```
To just print out the HTML code of the given `.md` file run:
```
md2html text.md
```
To print the HTML code into a `.txt` or `.html` file run:
```
md2html text.md text.html
```
If you pass a `.html` file for the output it will automatically add a basic HTML5 structure.

1527
md2html/libs/Parsedown.php Normal file

File diff suppressed because it is too large Load diff

76
md2html/md2html.php Executable file
View file

@ -0,0 +1,76 @@
#!/usr/bin/php
<?php
include '/opt/md2html/src/strings.php';
include '/opt/md2html/libs/Parsedown.php';
$parsedown = new Parsedown();
if(count($argv) == 1 || count($argv) > 3) {
echo "Arguments not possible.\n";
echo $usage;
} elseif (isset($argv[2])) {
if(substr_compare($argv[1], ".md", -3) == 0){
if(substr_compare($argv[2], ".txt", -4) == 0 ||
substr_compare($argv[2], ".html", -5) == 0) {
if(file_exists($argv[1])){
$handler = fopen($argv[1], "r");
$content = fread($handler, filesize($argv[1]));
fclose($handler);
$content = $parsedown
->setBreaksEnabled(true)
->text($content);
if(file_exists($argv[2])){
echo "The file $argv[2] already exists.\nDo you want to override it? (Y)es / (N)o ";
$answer = trim(fgets(STDIN));
if(in_array($answer, array("y","yes","Yes","YES","Y"))) {
$whandler = fopen($argv[2], "w+");
if(substr_compare($argv[2], ".html", -5) == 0){
$content = $htmlbegin . $content . $htmlend;
}
if(fwrite($whandler, $content)){
echo "File sucessfully written.";
} else {
echo "An error occured.";
}
fclose($whandler);
} else {
echo "File not changed.";
}
} else {
$whandler = fopen($argv[2], "x");
if(substr_compare($argv[2], ".html", -5) == 0){
$content = $htmlbegin . $content . $htmlend;
}
if(fwrite($whandler, $content)){
echo "HTML file sucessfully written.";
} else {
echo "An error occured.";
}
fclose($whandler);
}
}
} else {
echo "The output file is neither a HTML file nor a TXT file.";
}
} else {
echo "This is not a Markdown file!";
}
} elseif(isset($argv[1])){
if(in_array($argv[1], array("--help","-h","-?","--usage","-u"))) {
echo $usage;
} else {
if(substr_compare($argv[1], ".md", -3) == 0){
if(file_exists($argv[1])){
$handler = fopen($argv[1], "r");
$content = fread($handler, filesize($argv[1]));
fclose($handler);
echo $parsedown
->setBreaksEnabled(true)
->text($content);
} else {
echo "The given file doesn't exist.";
}
} else {
echo "This is not a Markdown file!";
}
}
}
echo "\n";

41
md2html/src/strings.php Normal file
View file

@ -0,0 +1,41 @@
<?php
$usage =
"
md2html converter
mmk2410 2015
MIT License
Usage:
./md2html inputfile [outputfile]
If no output file is given, the converted code will printed in the console.
The input file must be a .md file and the outputfile a html or txt.
./md2html.php argument
Available arguments:
-h | --help
Prints this text
If no output file is given, the converted code will printed in the console.
";
$htmlbegin =
"
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title></title>
</head>
<body>
";
$htmlend =
"
</body>
</html>
";