Skip to content

Commit

Permalink
breaking: upgarde to php 8.0, update some deps
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 6, 2021
1 parent 71f2cb5 commit 9d3fdff
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
46 changes: 15 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
60 changes: 33 additions & 27 deletions src/CliMarkdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -73,23 +77,23 @@ 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));
}

/**
* @param string $text
*
* @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);
}

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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']);
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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
*/
Expand All @@ -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;
}
}

0 comments on commit 9d3fdff

Please sign in to comment.