diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 1166d3f..ae169ee 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: true matrix: - php: [7.3, 7.4, 8.0] # 7.2, + php: [8.0, 8.1] # 7.2, os: [ubuntu-latest, macOS-latest] # windows-latest, # include: # will not testing on php 7.2 # - os: 'ubuntu-latest' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e42d9b9..a60b761 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -44,37 +44,21 @@ jobs: echo "release tag: ${tag1}" composer update --no-progress - # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" - # Docs: https://getcomposer.org/doc/articles/scripts.md - - # https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context - # - name: Generate changelog file - # id: changelog - # run: | - # php bin/kite gh cl prev $RELEASE_TAG --style gh-release --no-merges --fetch-tags --unshallow --file tmp/changelog-${RELEASE_TAG}.md - # cat tmp/changelog-${RELEASE_TAG}.md - - # https://github.com/meeDamian/github-release -# - name: Create release and upload assets -# uses: meeDamian/github-release@2.0 -# with: -# gzip: false -# token: ${{ secrets.GITHUB_TOKEN }} -# tag: ${{ env.RELEASE_TAG }} -# name: ${{ env.RELEASE_TAG }} -# body: | -# ${{ steps.changelog.outputs.CHLOGBODY }} -# files: kite-${{ env.RELEASE_TAG }}.phar + # more see https://github.com/inhere/kite + - name: Generate changelog file + id: changelog + run: | + wget -c -q https://github.com/inhere/kite/releases/latest/download/kite.phar + php kite.phar git cl prev last --style gh-release --no-merges --fetch-tags --unshallow --file changelog.md + cat changelog.md # https://github.com/softprops/action-gh-release - name: Create release and upload assets - uses: softprops/action-gh-release@v1 -# if: startsWith(github.ref, 'refs/tags/') - with: - name: ${{ env.RELEASE_TAG }} - tag_name: ${{ env.RELEASE_TAG }} - # body_path: tmp/changelog-${{ env.RELEASE_TAG }}.md - # files: kite-${{ env.RELEASE_TAG }}.phar - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -# GITHUB_REPOSITORY: my_gh_org/my_gh_repo \ No newline at end of file + uses: softprops/action-gh-release@v1 + # if: startsWith(github.ref, 'refs/tags/') + with: + name: ${{ env.RELEASE_TAG }} + tag_name: ${{ env.RELEASE_TAG }} + body_path: changelog.md + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 6df05e2..175deab 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # CLI-Markdown [![License](https://img.shields.io/packagist/l/phppkg/cli-markdown.svg?style=flat-square)](LICENSE) -[![Php Version](https://img.shields.io/badge/php-%3E=7.2.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/phppkg/cli-markdown) +[![Php Version](https://img.shields.io/badge/php-%3E=8.0.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/phppkg/cli-markdown) [![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/phppkg/cli-markdown)](https://github.com/phppkg/cli-markdown) [![Actions Status](https://github.com/phppkg/cli-markdown/workflows/Unit-Tests/badge.svg)](https://github.com/phppkg/cli-markdown/actions) diff --git a/composer.json b/composer.json index 14a09a7..8a37af4 100644 --- a/composer.json +++ b/composer.json @@ -11,10 +11,10 @@ } ], "require": { - "php": ">7.1.0", + "php": ">8.0.0", "ext-mbstring": "*", "cebe/markdown": "^1.2", - "toolkit/cli-utils":"~1.0" + "toolkit/cli-utils":"~2.0" }, "autoload": { "psr-4": { diff --git a/src/CliMarkdown.php b/src/CliMarkdown.php index f093df1..38804cb 100644 --- a/src/CliMarkdown.php +++ b/src/CliMarkdown.php @@ -6,10 +6,14 @@ use Toolkit\Cli\Color; use Toolkit\Cli\ColorTag; use function array_merge; +use function array_sum; +use function count; use function explode; use function implode; use function ltrim; +use function mb_strlen; use function sprintf; +use function str_pad; use function str_repeat; use function str_replace; use function strpos; @@ -51,19 +55,19 @@ class CliMarkdown extends GithubMarkdown * * @var string */ - private $lang; + private string $lang; /** * @var array */ - private $theme = self::THEME_DEFAULT; + private array $theme = self::THEME_DEFAULT; /** * Class constructor. * * @param string $lang */ - public function __construct(string $lang = 'en') + public function __construct(string $lang = '') { $this->lang = $lang; } @@ -73,11 +77,11 @@ public function __construct(string $lang = 'en') * * @return string */ - public function render(string $text): string + public function parse($text): string { - $parsed = $this->parse($text); - - return Color::parseTag($parsed); + $parsed = parent::parse($text); + + return str_replace(["\n\n\n", "\n\n\n\n"], "\n\n", ltrim($parsed)); } /** @@ -85,11 +89,11 @@ public function render(string $text): string * * @return string */ - public function parse($text): string + public function render(string $text): string { - $parsed = parent::parse($text); + $parsed = $this->parse($text); - return str_replace(["\n\n\n", "\n\n\n\n"], "\n\n", ltrim($parsed)); + return Color::parseTag($parsed); } /** @@ -151,7 +155,7 @@ protected function renderTable($block): string $head = $body = ''; // $cols = $block['cols']; - $tabInfo = ['width' => 60]; + $tabInfo = ['width' => 60]; $colWidths = []; foreach ($block['rows'] as $row) { foreach ($row as $c => $cell) { @@ -168,7 +172,7 @@ protected function renderTable($block): string $colCount = count($colWidths); $tabWidth = (int)array_sum($colWidths); - $first = true; + $first = true; $splits = []; foreach ($block['rows'] as $row) { // $cellTag = $first ? 'th' : 'td'; @@ -178,7 +182,7 @@ protected function renderTable($block): string // ︱||—― ̄====▪▪▭▭▃▃▄▄▁▁▕▏▎┇╇══ if ($first) { - $splits[] = str_pad('=', $cellLen+1, '='); + $splits[] = str_pad('=', $cellLen + 1, '='); } $lastIdx = count($cell) - 1; @@ -254,7 +258,7 @@ protected function renderAutoUrl($block): string $tag = $this->theme['link']; $url = $text = $block[1]; - if (strpos($url, self::GITHUB_HOST) !== false) { + if (str_contains($url, self::GITHUB_HOST)) { $text = substr($text, 19); } @@ -268,7 +272,7 @@ protected function renderAutoUrl($block): string */ protected function renderImage($block): string { - return self::NL . Color::addTag( '▨ ' . $block['orig'], $this->theme['image']); + return self::NL . Color::addTag('▨ ' . $block['orig'], $this->theme['image']); } /** @@ -317,7 +321,9 @@ protected function renderStrong($block): string { $text = $this->renderAbsy($block[1]); - return self::NL . ColorTag::add("**$text**", $this->theme['strong']) . self::NL; + return ColorTag::add("**$text**", $this->theme['strong']); + + // return self::NL . ColorTag::add("**$text**", $this->theme['strong']) . self::NL; } /** @@ -330,17 +336,6 @@ protected function renderText($block): string return $block[1]; } - /** - * @param int $len1 - * @param int $len2 - * - * @return int - */ - private function compareMax(int $len1, int $len2): int - { - return $len1 > $len2 ? $len1 : $len2; - } - /** * @return array */ @@ -356,4 +351,15 @@ public function setTheme(array $theme): void { $this->theme = array_merge($this->theme, $theme); } + + /** + * @param int $len1 + * @param int $len2 + * + * @return int + */ + private function compareMax(int $len1, int $len2): int + { + return $len1 > $len2 ? $len1 : $len2; + } }