Skip to content

Commit

Permalink
add file ability, php-cs-fixer, prepare changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed May 28, 2017
1 parent ccccb89 commit a24e3fc
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 51 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](http://semver.org/).

1.0.2 (in progress)
1.0.2 (28. May 2017)
-------------------

+ Added Unit Tests
+ Added ability to provide a file instead of a folder.
+ Added Unit Tests.
+ Added dry mode.

1.0.1 (28. May 2017)
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
[![Total Downloads](https://poser.pugx.org/nadar/github-markdown-fixer/downloads)](https://packagist.org/packages/nadar/github-markdown-fixer)
[![Latest Stable Version](https://poser.pugx.org/nadar/github-markdown-fixer/v/stable)](https://packagist.org/packages/nadar/github-markdown-fixer)

This project fixes your markdown files in order to have render them nicly withing GitHub.
This project fixes your Markdown files in order to render them nicely with GitHub and other Renderers.

Currently built in features:

+ Replace all tabs with 4 spaces.
+ Find Breaking Spaces and replace them with normal spaces. [GitHub Markdown Renderer problems with Breaking Spaces](https://github.com/github/markup/issues/1054#issuecomment-300061967).
+ Find none breaking spaces problem. [github/markup issue problem description](https://github.com/github/markup/issues/1054#issuecomment-300061967).

![GitHub Markdown Fixer in Action](screenshot.png)

## Usage

Add ths github markdown fixer to your project, within the `require-dev` section:
Add the `nadar/github-markdown-fixer` to your project, within the `require-dev` section:

> IF YOU GET A MINIMUM STABILITY / COMPOSER ERROR USE: `"minimum-stability" : "RC"` IN YOUR COMPOSER.JSON.
Expand All @@ -31,4 +33,4 @@ Go into your Terminal an run the Fixer:

|argument|description
|--------|----------
|--dry |run command in dry mode, does not change file contents.
|--dry |run command in dry mode, does not change file contents.
104 changes: 59 additions & 45 deletions src/FixController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,71 @@

/**
* Fix Markdown Files.
*
*
*
* Provide Folder:
*
* ```
* ./vendor/bin/gmf fix /folder
* ```
*
* Provide File:
* ```
* ./vendor/bin/gmf file /path/to/README.md
* ```
*
* @author Basil Suter <[email protected]>
*/
class FixController extends Command
{
/**
* @var boolean Whether to run the command but doe not change the file content.
*/
public $dry = false;
/**
*
* {@inheritDoc}
* @see \luya\console\Command::options()
*/
public function options($actionID)
{
return ['dry'];
}
/**
*
* {@inheritDoc}
* @see \yii\console\Controller::optionAliases()
*/
public function optionAliases()
{
return ['d' => 'dry'];
}
/**
* Fixing files inside a given Folder.
*
* @param string $folder The folder where the markdown files are located.
* @return integer
*/
/**
* @var boolean Whether to run the command but doe not change the file content.
*/
public $dry = false;
/**
*
* {@inheritDoc}
* @see \luya\console\Command::options()
*/
public function options($actionID)
{
return ['dry'];
}
/**
*
* {@inheritDoc}
* @see \yii\console\Controller::optionAliases()
*/
public function optionAliases()
{
return ['d' => 'dry'];
}
/**
* Fixing files inside a given Folder.
*
* @param string $folder The folder where the markdown files are located or a single file
* @return integer
*/
public function actionIndex($folder)
{
$files = FileHelper::findFiles($folder, [
'recursive' => true,
'caseSensitive' => false,
'only'=> ['*.md'],
]);
if (is_file($folder)) {
$files[] = $folder;
} else {
$files = FileHelper::findFiles($folder, [
'recursive' => true,
'caseSensitive' => false,
'only'=> ['*.md'],
]);
}

foreach ($files as $file) {
$content = $this->getFileContent($file);

if (!$content) {
$this->outputError("Unable to read file: " . $file);
continue;
$this->outputError("Unable to read file: " . $file);
continue;
}

$newcontent = $this->parseContent($content);
Expand All @@ -67,7 +81,7 @@ public function actionIndex($folder)
}

if (!$this->dry) {
file_put_contents($file, $newcontent);
file_put_contents($file, $newcontent);
}
}

Expand All @@ -81,18 +95,18 @@ public function actionIndex($folder)
*/
public function getFileContent($file)
{
return FileHelper::getFileContent($file);
return FileHelper::getFileContent($file);
}

/**
* Parse Content of a File and replace if required.
*
*
* @param string $content The content to fix
* @return string The fixed content.
*/
public function parseContent($content)
{
// replace breaking spaces with spaces
// replace breaking spaces with spaces
$content = preg_replace('/xC2xA0/', ' ', $content);
$content = preg_replace('~\x{00a0}~siu', ' ', $content);

Expand All @@ -101,4 +115,4 @@ public function parseContent($content)

return $content;
}
}
}

0 comments on commit a24e3fc

Please sign in to comment.