-
-
Save Danack/33a0dbd2f1812c4a15e95b620ee123a4 to your computer and use it in GitHub Desktop.
convert docuwiki.
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 | |
declare(strict_types = 1); | |
function convert_file_to_markdown(string $file) | |
{ | |
$changes = [ | |
// Titles | |
'#======(.*)======#iu' => '#\1', | |
'#=====(.*)=====#iu' => '##\1', | |
'#====(.*)====#iu' => '###\1', | |
'#===(.*)===#iu' => '####\1', | |
"#\[\[(.+)\|(.+)\]\]#iu" => '[\2](\1)', | |
"#''#iu" => '`', | |
'#<code (.+)>#iu' => '``` \1', | |
'#</code>#iu' => '```', | |
'#%%(.*)%%#iu' => '``` \1', | |
'#<nowiki>(.*)</nowiki>#iu' => '\1' | |
]; | |
$filename = $file . '.docuwiki'; | |
$contents = file_get_contents($filename); | |
if ($contents === false) { | |
echo "Failed to read file $filename"; | |
exit(-1); | |
} | |
$new_contents = preg_replace( | |
array_keys($changes), | |
array_values($changes), | |
$contents | |
); | |
$new_filename = $filename = $file . '_test.md'; | |
$file_written = file_put_contents( | |
$new_filename, | |
$new_contents | |
); | |
if ($file_written !== false) { | |
echo "yay, written\n"; | |
} | |
else { | |
echo "Boo, not written, written\n"; | |
} | |
} | |
function convert_file_to_docuwiki(string $file) | |
{ | |
} | |
function convert_file(string $file) | |
{ | |
if (file_exists($file . '.docuwiki') === true) { | |
convert_file_to_markdown($file); | |
} | |
else if (file_exists($file . '.md') === true) { | |
convert_file_to_docuwiki($file); | |
} | |
else { | |
echo "Couldn't find $file to convert."; | |
exit(-1); | |
} | |
} | |
function convert_files() | |
{ | |
$files = [ | |
// 'function_autoloading', | |
// 'magic_signatures', | |
'2_autoloading_for_all_types' | |
]; | |
foreach ($files as $file) { | |
convert_file($file); | |
} | |
} | |
convert_files(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment