Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
Docblock
  • Loading branch information
u01jmg3 committed Dec 30, 2018
1 parent d51ff98 commit a77f47e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
19 changes: 10 additions & 9 deletions docx2md.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ private function docx2md(array $args, $isTestMode = false)
$options = getopt($shortOptions, $longOptionsArray);

if ($options) {
$shortOptionsArray = array_map(function($item) {
$shortOptionsArray = array_map(function ($item) {
return rtrim($item, ':');
}, $shortOptionsArray);
$longOptionsArray = array_map(function($item) {
$longOptionsArray = array_map(function ($item) {
return rtrim($item, ':');
}, $longOptionsArray);

Expand Down Expand Up @@ -172,7 +172,7 @@ private function docx2md(array $args, $isTestMode = false)
$output .= 'If no destination file is specified, output will be written to the console excluding any images.';
$output .= PHP_EOL;
die($output);
} else if (empty($optionDebug)) {
} elseif (empty($optionDebug)) {
// If option is set and not already in test mode
// run tests and *continue on* with converting
if (!empty($optionTest) && !$isTestMode) {
Expand All @@ -195,7 +195,7 @@ private function docx2md(array $args, $isTestMode = false)
foreach ($args as $index => $arg) {
if ($index === 0) {
$docxFilename = $args[$index];
} else if ($index === 1) {
} elseif ($index === 1) {
$mdFilename = $args[$index];
}
}
Expand All @@ -220,7 +220,7 @@ private function docx2md(array $args, $isTestMode = false)
if (!$isTestMode && $mdFilename !== null) {
if ($hasMultipleFiles) {
$mdFilename = basename($docxFilename, 'docx') . 'md';
} else if (file_exists($mdFilename)) {
} elseif (file_exists($mdFilename)) {
// Generate a random extension so as not to overwrite destination filename
$mdFilename = $mdFilename . '.' . substr(md5(uniqid(rand(), true)), 0, 5);
}
Expand Down Expand Up @@ -265,6 +265,7 @@ private function docx2md(array $args, $isTestMode = false)
} else {
$this->extractFolder($zip, 'word/media', $documentFolder);
}

$zip->extractTo($documentFolder, array('word/document.xml', 'word/_rels/document.xml.rels'));
$zip->close();
} else {
Expand All @@ -285,7 +286,7 @@ private function docx2md(array $args, $isTestMode = false)
$xml = $wordDocument->saveXML();

// libxml < 2.7 fix
$xml = str_replace('r:id=', 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id=', $xml);
$xml = str_replace('r:id=', 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id=', $xml);
$xml = str_replace('r:embed=', 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed=', $xml);

$mainDocument = new \DOMDocument(self::VERSION, self::ENCODING);
Expand Down Expand Up @@ -632,10 +633,10 @@ private function cleanData($data)
/**
* Test markdown converter
*
* @param $args
* @param array $args
* @return void
*/
private function runTests($args)
private function runTests(array $args)
{
$src = 'examples';
$formatter = ' %s. %s' . self::WHITE . ': %s' . PHP_EOL;
Expand Down Expand Up @@ -1098,4 +1099,4 @@ private function runTests($args)
// Create class automagically when executed on the command line
if (php_sapi_name() === Docx2md::PHP_SAPI_NAME) {
new Docx2md($argv);
}
}
5 changes: 3 additions & 2 deletions examples/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
$converter = new Docx2md\Docx2md;

$files = glob('docx/*.docx', GLOB_BRACE);

foreach ($files as $file) {
$result = $converter->parseFile($file);

print_r($result->metadata);
echo '<br><br>';

echo '<br><br>';
echo nl2br($result->markdown, false);
echo '<br><br>';
}
}

0 comments on commit a77f47e

Please sign in to comment.