From 2eb7d535b491b241b99aaacaa7acf932710ea4c5 Mon Sep 17 00:00:00 2001 From: Ludolph Neethling Date: Sun, 19 Feb 2012 02:35:06 +0200 Subject: [PATCH] Hacked and most probably broken some part to help me convert DokuWiki to Markdown. --- .gitignore | 5 ++++- README.md | 30 ++++++++++++++--------------- scripts/DocuwikiToMarkdownExtra.php | 13 ++++++++++--- scripts/TranslateSSDocs.php | 18 ++++++++++++++++- template.txt | 4 ++++ 5 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 template.txt diff --git a/.gitignore b/.gitignore index 496ee2c..d7707e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -.DS_Store \ No newline at end of file +.DS_Store +/en +/output +/run.bat \ No newline at end of file diff --git a/README.md b/README.md index e6dc8d6..951efde 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,8 @@ -# SilverStripe Documentation Restructuring Project +# Liquibase DokuWiki to Markdown Converter -Tools to convert the original SilverStripe documentation wiki (based on DokuWiki syntax) -to the new Markdown-driven [doc.silverstripe.org](http://doc.silverstripe.org). +## Introduction -**UPDATE: The conversion has been completed. Please apply any content changes against the [github.com/silverstripe/sapphire](http://github.com/silverstripe/sapphire) and [github.com/silverstripe/silverstripe-cms](http://github.com/silverstripe/silverstripe-cms) repositories.** - - * [Mailinglist](http://groups.google.com/group/silverstripe-documentation) - * [Planning wiki page](http://doc.silverstripe.org/tmp:documentation-restructuring) - * [TODO list and bugtracker](http://open.silverstripe.org/query?status=inprogress&status=new&status=replyneeded&status=reviewed&component=Documentation&order=priority&col=id&col=summary&col=status&col=type&col=priority&col=milestone&col=component) - -## Contact - - * Documentation questions: Ingo Schommer (ingo at silverstripe dot com) - * Markdown Conversion: Mark Stephens (mark at silverstripe dot com) +Tools to convert the DokuWiki syntax to Markdown syntax. Please note it has some specific Liquibase regular expressions in `scripts/DocuwikiToMarkdownExtra.php`. ## Usage @@ -20,11 +10,21 @@ to the new Markdown-driven [doc.silverstripe.org](http://doc.silverstripe.org). ### Import DokuWiki files -Note: This is only possible by SilverStripe staff. +I don't have a idea how DokuWiki store its files so I'm leaving this note here if it might help. + +Note: This is only possible by SilverStripe staff. scp -P 2222 -r @doc.silverstripe.org:/sites/ss2doc/www/assets/data/pages/* input/ ### Convert to Markdown files cd scripts - php TranslateSSDocs.php ../input ../output \ No newline at end of file + php TranslateSSDocs.php ../input <../output> < template.txt> + +`../output` - if output is not supplied it will print the conversion to `stdout`. + +`template.txt` - at the moment it only prepends the content of the template to each file it converts. + +## Credit + +This project was shamelessly forked from the [SilverStripe Documentation Restructuring Project](https://github.com/chillu/silverstripe-doc-restructuring) and was hacked/broken apart to add some extra functionality. \ No newline at end of file diff --git a/scripts/DocuwikiToMarkdownExtra.php b/scripts/DocuwikiToMarkdownExtra.php index 168320d..7c739d6 100644 --- a/scripts/DocuwikiToMarkdownExtra.php +++ b/scripts/DocuwikiToMarkdownExtra.php @@ -48,8 +48,15 @@ class DocuwikiToMarkdownExtra { // Misc checks '/^\d*\.\s/' => array("notice" => "Possible numbered list item that is not docuwiki format, not handled"), - '/^=+\s*.*$/' => array("notice" => "Line starts with an =. Possibly an untranslated heading. Check for = in the heading text") + '/^=+\s*.*$/' => array("notice" => "Line starts with an =. Possibly an untranslated heading. Check for = in the heading text"), // email + + // extra rules for liquibase wiki + // remove liquibase.org + '/]\(http:\/\/liquibase\.org\/([^\)]*)\)/' => array("rewrite" => '](\1)'), + + // add .html and site template variables + '/]\(([^\)]*)\)/' => array("rewrite" => ']({{ site.url }}/{{ page.lang }}/\1.html)') ); // Contains the name of current input file being processed. @@ -316,13 +323,13 @@ function getLines($s) { // Convert a docuwiki file in the input directory and called // $filename, and re-created it in the output directory, translated // to markdown extra. - function convertFile($inputFile, $outputFile = null) { + function convertFile($inputFile, $outputFile = null, $flags = 0) { $this->fileName = $inputFile; $s = file_get_contents($inputFile); $s = $this->convert($s); if($outputFile) { - if (file_put_contents($outputFile, $s) === FALSE) + if (file_put_contents($outputFile, $s, $flags) === FALSE) echo "Could not write file {$outputFile}\n"; } diff --git a/scripts/TranslateSSDocs.php b/scripts/TranslateSSDocs.php index e0fd3ec..17dc7a1 100644 --- a/scripts/TranslateSSDocs.php +++ b/scripts/TranslateSSDocs.php @@ -13,6 +13,8 @@ $args = @$_SERVER['argv']; $inputDir = (isset($args[1])) ? realpath($args[1]) : "../input/"; $outputDir = (isset($args[2])) ? realpath($args[2]) : false; +echo "Output Path " , $outputDir, "\n"; +$template = (isset($args[3])) ? file_get_contents(realpath($args[3])) : false; require_once("DocuwikiToMarkdownExtra.php"); @@ -39,14 +41,28 @@ $inputDir = $object->getPath(); if (is_dir($object->getPathname())) continue; + + if($outputDir) { // Create output subfolder (optional) + // Was this here gor recursive code? $outputDir = str_replace($path, substr($path, 0, -5) . "output", $inputDir); + if (!file_exists($outputDir)) mkdir($outputDir, 0777, true); $outFilename = preg_replace('/\.txt$/', '.md', $filename); + if ($template) { + $flags = FILE_APPEND; + echo "Writing file ", "{$outputDir}/{$outFilename}" , "\n"; + if (file_put_contents("{$outputDir}/{$outFilename}", $template) === FALSE) + echo "Could not write file {$outputFile}\n"; + + } else { + $flags = 0; + } $converter->convertFile( "{$inputDir}/{$filename}", - "{$outputDir}/{$outFilename}" + "{$outputDir}/{$outFilename}", + $flags ); } else { echo $converter->convertFile( diff --git a/template.txt b/template.txt new file mode 100644 index 0000000..830e7a4 --- /dev/null +++ b/template.txt @@ -0,0 +1,4 @@ +--- +layout: liquibase +lang: en +---