Last active
October 20, 2020 14:28
-
-
Save fumikito/4230215 to your computer and use it in GitHub Desktop.
Githubのreadme.mdからWordPressプラグイン用のreame.txtをに変換するコマンドラインツール
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/opt/local/bin/php | |
| <?php | |
| // 1行目のシバンは環境に合わせて書き換えてください | |
| // `which php` とターミナルで打つと、パスがわかります。 | |
| $file = './readme.md'; | |
| if( !file_exists($file) ){ | |
| die("[Error] 現在のディレクトリにreadme.mdが存在しません".PHP_EOL); | |
| } | |
| echo "readme.mdを発見しました...\n"; | |
| $string = file_get_contents($file); | |
| //見出しを変更する | |
| $string = preg_replace_callback('/^(#+)\s+(.*)/mu', function($match){ | |
| $length = strlen($match[1]); | |
| $sep = ''; | |
| for($i = 1, $l = 3 - ($length - 1); $i <= $l; $i++){ | |
| $sep .= '='; | |
| } | |
| return "{$sep} {$match[2]} {$sep}"; | |
| }, $string); | |
| //保存 | |
| if(!file_put_contents('./readme.txt', $string)){ | |
| die("[Error] readme.txtを保存できませんでした。".PHP_EOL); | |
| } | |
| echo "readme.txtを生成しました...Done".PHP_EOL; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
こっちのリポジトリで管理しています。
https://github.com/fumikito/wp-readme