Skip to content

Instantly share code, notes, and snippets.

@fumikito
Last active October 20, 2020 14:28
Show Gist options
  • Select an option

  • Save fumikito/4230215 to your computer and use it in GitHub Desktop.

Select an option

Save fumikito/4230215 to your computer and use it in GitHub Desktop.
Githubのreadme.mdからWordPressプラグイン用のreame.txtをに変換するコマンドラインツール
#!/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;
@fumikito
Copy link
Copy Markdown
Author

こっちのリポジトリで管理しています。
https://github.com/fumikito/wp-readme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment