Skip to content

Instantly share code, notes, and snippets.

@Danack
Created May 24, 2020 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Danack/33a0dbd2f1812c4a15e95b620ee123a4 to your computer and use it in GitHub Desktop.
Save Danack/33a0dbd2f1812c4a15e95b620ee123a4 to your computer and use it in GitHub Desktop.
convert docuwiki.
<?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