Skip to content

Commit

Permalink
Hacked and most probably broken some part to help me convert DokuWiki…
Browse files Browse the repository at this point in the history
… to Markdown.
  • Loading branch information
Ludolph Neethling committed Feb 19, 2012
1 parent 2e0427f commit 2eb7d53
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
5 changes: 4 additions & 1 deletion .gitignore
@@ -1 +1,4 @@
.DS_Store
.DS_Store
/en
/output
/run.bat
30 changes: 15 additions & 15 deletions README.md
@@ -1,30 +1,30 @@
# 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

*Note: The following scripts should no longer be used, as they were designed for an earlier stage in the project.*

### 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 <username>@doc.silverstripe.org:/sites/ss2doc/www/assets/data/pages/* input/

### Convert to Markdown files

cd scripts
php TranslateSSDocs.php ../input ../output
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.
13 changes: 10 additions & 3 deletions scripts/DocuwikiToMarkdownExtra.php
Expand Up @@ -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"),
// <x@y.xom> 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.
Expand Down Expand Up @@ -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";
}

Expand Down
18 changes: 17 additions & 1 deletion scripts/TranslateSSDocs.php
Expand Up @@ -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");

Expand All @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions template.txt
@@ -0,0 +1,4 @@
---
layout: liquibase
lang: en
---

0 comments on commit 2eb7d53

Please sign in to comment.