From 3c2a7f802127d5fac5cd3ac9444e43e8169b4ca0 Mon Sep 17 00:00:00 2001 From: Nima HeydariNasab Date: Wed, 28 Aug 2024 18:51:28 +0330 Subject: [PATCH 1/5] Fix for extra added spaces at the start of lines --- src/Languages/Base/Injections/GutterInjection.php | 2 +- src/Themes/Css/andromeeda.css | 1 + src/Themes/Css/aurora-x.css | 1 + src/Themes/Css/ayu-dark.css | 1 + src/Themes/Css/catppuccin-frappe.css | 1 + src/Themes/Css/catppuccin-latte.css | 1 + src/Themes/Css/catppuccin-macchiato.css | 1 + src/Themes/Css/catppuccin-mocha.css | 1 + src/Themes/Css/dark-plus.css | 1 + src/Themes/Css/dracula-soft.css | 1 + src/Themes/Css/dracula.css | 1 + src/Themes/Css/github-dark-default.css | 1 + src/Themes/Css/github-dark-dimmed.css | 1 + src/Themes/Css/github-dark.css | 1 + src/Themes/Css/github-light-default.css | 1 + src/Themes/Css/github-light.css | 1 + src/Themes/Css/highlight-light-lite.css | 1 + src/Themes/Css/houston.css | 1 + src/Themes/Css/inspired-github.css | 1 + src/Themes/Css/light-plus.css | 1 + src/Themes/Css/material-theme-darker.css | 1 + src/Themes/Css/material-theme-lighter.css | 1 + src/Themes/Css/material-theme-ocean.css | 1 + src/Themes/Css/material-theme-palenight.css | 1 + src/Themes/Css/material-theme.css | 1 + src/Themes/Css/min-dark.css | 1 + src/Themes/Css/min-light.css | 1 + src/Themes/Css/monokai.css | 1 + src/Themes/Css/night-owl.css | 1 + src/Themes/Css/nord.css | 1 + src/Themes/Css/one-dark-pro.css | 1 + src/Themes/Css/poimandres.css | 1 + src/Themes/Css/red.css | 1 + src/Themes/Css/rose-pine-dawn.css | 1 + src/Themes/Css/rose-pine-moon.css | 1 + src/Themes/Css/rose-pine.css | 1 + src/Themes/Css/slack-dark.css | 1 + src/Themes/Css/slack-ochin.css | 1 + src/Themes/Css/solarized-dark.css | 1 + src/Themes/Css/solarized-light.css | 1 + src/Themes/Css/synthwave-84.css | 1 + src/Themes/Css/tokyo-night.css | 1 + src/Themes/Css/vesper.css | 1 + src/Themes/Css/vitesse-black.css | 1 + src/Themes/Css/vitesse-dark.css | 1 + src/Themes/Css/vitesse-light.css | 1 + 46 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/Languages/Base/Injections/GutterInjection.php b/src/Languages/Base/Injections/GutterInjection.php index ac5d008..00eb766 100644 --- a/src/Languages/Base/Injections/GutterInjection.php +++ b/src/Languages/Base/Injections/GutterInjection.php @@ -62,7 +62,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio $gutterClass = 'hl-gutter' . ($hasClasses ? ' ' . $hasClasses : ''); $lines[$i] = sprintf( - Escape::tokens('%s %s'), + Escape::tokens('%s%s'), $gutterClass, str_pad( string: (string) $gutterNumber, diff --git a/src/Themes/Css/andromeeda.css b/src/Themes/Css/andromeeda.css index c834c00..ff78ebb 100644 --- a/src/Themes/Css/andromeeda.css +++ b/src/Themes/Css/andromeeda.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/aurora-x.css b/src/Themes/Css/aurora-x.css index 8ba7b98..5829a74 100644 --- a/src/Themes/Css/aurora-x.css +++ b/src/Themes/Css/aurora-x.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/ayu-dark.css b/src/Themes/Css/ayu-dark.css index 1f59ce4..3eb9da1 100644 --- a/src/Themes/Css/ayu-dark.css +++ b/src/Themes/Css/ayu-dark.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/catppuccin-frappe.css b/src/Themes/Css/catppuccin-frappe.css index 924b9dc..e305e36 100644 --- a/src/Themes/Css/catppuccin-frappe.css +++ b/src/Themes/Css/catppuccin-frappe.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/catppuccin-latte.css b/src/Themes/Css/catppuccin-latte.css index 1bffd5f..c1fd1b7 100644 --- a/src/Themes/Css/catppuccin-latte.css +++ b/src/Themes/Css/catppuccin-latte.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/catppuccin-macchiato.css b/src/Themes/Css/catppuccin-macchiato.css index 218ca5a..a1f3673 100644 --- a/src/Themes/Css/catppuccin-macchiato.css +++ b/src/Themes/Css/catppuccin-macchiato.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/catppuccin-mocha.css b/src/Themes/Css/catppuccin-mocha.css index e2639b5..78d546f 100644 --- a/src/Themes/Css/catppuccin-mocha.css +++ b/src/Themes/Css/catppuccin-mocha.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/dark-plus.css b/src/Themes/Css/dark-plus.css index fc0b86a..3d9d75e 100644 --- a/src/Themes/Css/dark-plus.css +++ b/src/Themes/Css/dark-plus.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/dracula-soft.css b/src/Themes/Css/dracula-soft.css index 7ae40f0..768bbed 100644 --- a/src/Themes/Css/dracula-soft.css +++ b/src/Themes/Css/dracula-soft.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/dracula.css b/src/Themes/Css/dracula.css index 2cfaa91..ff6a060 100644 --- a/src/Themes/Css/dracula.css +++ b/src/Themes/Css/dracula.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/github-dark-default.css b/src/Themes/Css/github-dark-default.css index 0e60b6e..625f913 100644 --- a/src/Themes/Css/github-dark-default.css +++ b/src/Themes/Css/github-dark-default.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/github-dark-dimmed.css b/src/Themes/Css/github-dark-dimmed.css index 6051fe5..aaa0f0d 100644 --- a/src/Themes/Css/github-dark-dimmed.css +++ b/src/Themes/Css/github-dark-dimmed.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/github-dark.css b/src/Themes/Css/github-dark.css index fe6dd50..13af819 100644 --- a/src/Themes/Css/github-dark.css +++ b/src/Themes/Css/github-dark.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/github-light-default.css b/src/Themes/Css/github-light-default.css index de355df..409c1e7 100644 --- a/src/Themes/Css/github-light-default.css +++ b/src/Themes/Css/github-light-default.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/github-light.css b/src/Themes/Css/github-light.css index ff31ca6..222c893 100644 --- a/src/Themes/Css/github-light.css +++ b/src/Themes/Css/github-light.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/highlight-light-lite.css b/src/Themes/Css/highlight-light-lite.css index a35560a..8d8cbb6 100644 --- a/src/Themes/Css/highlight-light-lite.css +++ b/src/Themes/Css/highlight-light-lite.css @@ -64,6 +64,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/houston.css b/src/Themes/Css/houston.css index 5c1e9ff..0f0d910 100644 --- a/src/Themes/Css/houston.css +++ b/src/Themes/Css/houston.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/inspired-github.css b/src/Themes/Css/inspired-github.css index 8cd53a9..b70606d 100644 --- a/src/Themes/Css/inspired-github.css +++ b/src/Themes/Css/inspired-github.css @@ -81,6 +81,7 @@ pre, code { font-size: 0.9em; color: #b3b3b3; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/light-plus.css b/src/Themes/Css/light-plus.css index b59efb0..01c3890 100644 --- a/src/Themes/Css/light-plus.css +++ b/src/Themes/Css/light-plus.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/material-theme-darker.css b/src/Themes/Css/material-theme-darker.css index f4c112f..0e8f4dd 100644 --- a/src/Themes/Css/material-theme-darker.css +++ b/src/Themes/Css/material-theme-darker.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/material-theme-lighter.css b/src/Themes/Css/material-theme-lighter.css index 6de8a47..52f121f 100644 --- a/src/Themes/Css/material-theme-lighter.css +++ b/src/Themes/Css/material-theme-lighter.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/material-theme-ocean.css b/src/Themes/Css/material-theme-ocean.css index a8c4a64..e4ba033 100644 --- a/src/Themes/Css/material-theme-ocean.css +++ b/src/Themes/Css/material-theme-ocean.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/material-theme-palenight.css b/src/Themes/Css/material-theme-palenight.css index cdd6504..86dd1be 100644 --- a/src/Themes/Css/material-theme-palenight.css +++ b/src/Themes/Css/material-theme-palenight.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/material-theme.css b/src/Themes/Css/material-theme.css index a6e9fc7..d8c0cae 100644 --- a/src/Themes/Css/material-theme.css +++ b/src/Themes/Css/material-theme.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/min-dark.css b/src/Themes/Css/min-dark.css index fa5f511..0a5a399 100644 --- a/src/Themes/Css/min-dark.css +++ b/src/Themes/Css/min-dark.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/min-light.css b/src/Themes/Css/min-light.css index 029af8d..c7b2784 100644 --- a/src/Themes/Css/min-light.css +++ b/src/Themes/Css/min-light.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/monokai.css b/src/Themes/Css/monokai.css index ba06580..2d46581 100644 --- a/src/Themes/Css/monokai.css +++ b/src/Themes/Css/monokai.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/night-owl.css b/src/Themes/Css/night-owl.css index 479c54a..a586361 100644 --- a/src/Themes/Css/night-owl.css +++ b/src/Themes/Css/night-owl.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/nord.css b/src/Themes/Css/nord.css index b9f41cb..ada0525 100644 --- a/src/Themes/Css/nord.css +++ b/src/Themes/Css/nord.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/one-dark-pro.css b/src/Themes/Css/one-dark-pro.css index 72e898f..407e768 100644 --- a/src/Themes/Css/one-dark-pro.css +++ b/src/Themes/Css/one-dark-pro.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/poimandres.css b/src/Themes/Css/poimandres.css index 67c0f9b..c26fb51 100644 --- a/src/Themes/Css/poimandres.css +++ b/src/Themes/Css/poimandres.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/red.css b/src/Themes/Css/red.css index a8bf987..4a0835b 100644 --- a/src/Themes/Css/red.css +++ b/src/Themes/Css/red.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/rose-pine-dawn.css b/src/Themes/Css/rose-pine-dawn.css index 0faedac..309fe53 100644 --- a/src/Themes/Css/rose-pine-dawn.css +++ b/src/Themes/Css/rose-pine-dawn.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/rose-pine-moon.css b/src/Themes/Css/rose-pine-moon.css index c79406b..7fa55d6 100644 --- a/src/Themes/Css/rose-pine-moon.css +++ b/src/Themes/Css/rose-pine-moon.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/rose-pine.css b/src/Themes/Css/rose-pine.css index c64753b..e9fd3bd 100644 --- a/src/Themes/Css/rose-pine.css +++ b/src/Themes/Css/rose-pine.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/slack-dark.css b/src/Themes/Css/slack-dark.css index 9a5973f..cc2bd7d 100644 --- a/src/Themes/Css/slack-dark.css +++ b/src/Themes/Css/slack-dark.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/slack-ochin.css b/src/Themes/Css/slack-ochin.css index b3979ff..eff9a1d 100644 --- a/src/Themes/Css/slack-ochin.css +++ b/src/Themes/Css/slack-ochin.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/solarized-dark.css b/src/Themes/Css/solarized-dark.css index c58701d..d2cf89f 100644 --- a/src/Themes/Css/solarized-dark.css +++ b/src/Themes/Css/solarized-dark.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/solarized-light.css b/src/Themes/Css/solarized-light.css index fbf93de..8095942 100644 --- a/src/Themes/Css/solarized-light.css +++ b/src/Themes/Css/solarized-light.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/synthwave-84.css b/src/Themes/Css/synthwave-84.css index 5ef7da3..c71a8f0 100644 --- a/src/Themes/Css/synthwave-84.css +++ b/src/Themes/Css/synthwave-84.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/tokyo-night.css b/src/Themes/Css/tokyo-night.css index 53296cc..4484eab 100644 --- a/src/Themes/Css/tokyo-night.css +++ b/src/Themes/Css/tokyo-night.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/vesper.css b/src/Themes/Css/vesper.css index fdf016e..7732b24 100644 --- a/src/Themes/Css/vesper.css +++ b/src/Themes/Css/vesper.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/vitesse-black.css b/src/Themes/Css/vitesse-black.css index fc6839d..a099549 100644 --- a/src/Themes/Css/vitesse-black.css +++ b/src/Themes/Css/vitesse-black.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/vitesse-dark.css b/src/Themes/Css/vitesse-dark.css index eeb022b..cc3ea2b 100644 --- a/src/Themes/Css/vitesse-dark.css +++ b/src/Themes/Css/vitesse-dark.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } diff --git a/src/Themes/Css/vitesse-light.css b/src/Themes/Css/vitesse-light.css index 93acd67..fb7cfb0 100644 --- a/src/Themes/Css/vitesse-light.css +++ b/src/Themes/Css/vitesse-light.css @@ -72,6 +72,7 @@ pre, code { font-size: 0.9em; color: #555; padding: 0 1ch; + margin-right: 1ch; user-select: none; } From 33e44c2b9030311ad8e4f22880462ef7b4bf30c1 Mon Sep 17 00:00:00 2001 From: Nima HeydariNasab Date: Wed, 28 Aug 2024 19:39:46 +0330 Subject: [PATCH 2/5] Fix for gutter spacing in terminal themes --- src/Languages/Base/Injections/GutterInjection.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Languages/Base/Injections/GutterInjection.php b/src/Languages/Base/Injections/GutterInjection.php index 00eb766..75cceb9 100644 --- a/src/Languages/Base/Injections/GutterInjection.php +++ b/src/Languages/Base/Injections/GutterInjection.php @@ -5,6 +5,7 @@ namespace Tempest\Highlight\Languages\Base\Injections; use Tempest\Highlight\Escape; +use Tempest\Highlight\TerminalTheme; use Tempest\Highlight\Highlighter; use Tempest\Highlight\Injection; use Tempest\Highlight\ParsedInjection; @@ -62,7 +63,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio $gutterClass = 'hl-gutter' . ($hasClasses ? ' ' . $hasClasses : ''); $lines[$i] = sprintf( - Escape::tokens('%s%s'), + Escape::tokens('%s'.($highlighter->getTheme() instanceof TerminalTheme ? ' ' : '').'%s'), $gutterClass, str_pad( string: (string) $gutterNumber, From 97ec0d6631d0e3215772f0ce830eff06858d5997 Mon Sep 17 00:00:00 2001 From: Nima HeydariNasab Date: Wed, 28 Aug 2024 19:39:55 +0330 Subject: [PATCH 3/5] Fix for gutter tests --- tests/CommonMark/CodeBlockRendererTest.php | 2 +- .../Base/Injections/GutterInjectionTest.php | 58 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/CommonMark/CodeBlockRendererTest.php b/tests/CommonMark/CodeBlockRendererTest.php index 3febb79..42af8e1 100644 --- a/tests/CommonMark/CodeBlockRendererTest.php +++ b/tests/CommonMark/CodeBlockRendererTest.php @@ -53,7 +53,7 @@ class Foo {} TXT; $expected = <<<'TXT' -
10 class Foo {}
+
10class Foo {}
TXT; diff --git a/tests/Languages/Base/Injections/GutterInjectionTest.php b/tests/Languages/Base/Injections/GutterInjectionTest.php index 92d0457..09fe1ae 100644 --- a/tests/Languages/Base/Injections/GutterInjectionTest.php +++ b/tests/Languages/Base/Injections/GutterInjectionTest.php @@ -32,22 +32,22 @@ public function test_gutter_injection(): void TXT; $expected = <<<'TXT' - 10 foreach ($lines as $i => $line) { - 11 $gutterNumber = $gutterNumbers[$i]; - 12 - 13 $gutterClass = 'hl-gutter ' . ($this->classes[$i + 1] ?? ''); -14 + -15 + $lines[$i] = sprintf( -16 + Escape::tokens('<span class="%s">%s</span>%s'), - 17 $gutterClass, - 18 str_pad( -19 - string: $gutterNumber, - 20 length: $gutterWidth, - 21 pad_type: STR_PAD_LEFT, - 22 ), - 23 $line, - 24 ); - 25 } + 10foreach ($lines as $i => $line) { + 11 $gutterNumber = $gutterNumbers[$i]; + 12 + 13 $gutterClass = 'hl-gutter ' . ($this->classes[$i + 1] ?? ''); +14 + +15 + $lines[$i] = sprintf( +16 + Escape::tokens('<span class="%s">%s</span>%s'), + 17 $gutterClass, + 18 str_pad( +19 - string: $gutterNumber, + 20 length: $gutterWidth, + 21 pad_type: STR_PAD_LEFT, + 22 ), + 23 $line, + 24 ); + 25} TXT; $highlighter = (new Highlighter())->withGutter(10); @@ -65,11 +65,11 @@ public function test_gutter_injection_one_single_line(): void TXT; $expected = <<<'TXT' - 10 on: - 11 pull_request: - 12 types: [opened, synchronize, reopened, ready_for_review] -13 + pull_request_target: - 14 other: foo + 10on: + 11 pull_request: + 12 types: [opened, synchronize, reopened, ready_for_review] +13 + pull_request_target: + 14other: foo TXT; $highlighter = (new Highlighter())->withGutter(10); @@ -91,14 +91,14 @@ public function test_gutter_injection_many_single_lines(): void TXT; $expected = <<<'TXT' - 10 on: - 11 pull_request: - 12 types: [opened, synchronize, reopened, ready_for_review] -13 + pull_request_target: -14 + types: [opened, synchronize, reopened, ready_for_review] -15 + types: [opened, synchronize, reopened, ready_for_review] -16 + types: [opened, synchronize, reopened, ready_for_review] - 17 other: foo + 10on: + 11 pull_request: + 12 types: [opened, synchronize, reopened, ready_for_review] +13 + pull_request_target: +14 + types: [opened, synchronize, reopened, ready_for_review] +15 + types: [opened, synchronize, reopened, ready_for_review] +16 + types: [opened, synchronize, reopened, ready_for_review] + 17other: foo TXT; $highlighter = (new Highlighter())->withGutter(10); From d6b0013270d85fcacc9025a61df6be36faa3029f Mon Sep 17 00:00:00 2001 From: Nima HeydariNasab Date: Wed, 28 Aug 2024 20:28:31 +0330 Subject: [PATCH 4/5] Fix ordered imports --- src/Languages/Base/Injections/GutterInjection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Languages/Base/Injections/GutterInjection.php b/src/Languages/Base/Injections/GutterInjection.php index 75cceb9..4fb4468 100644 --- a/src/Languages/Base/Injections/GutterInjection.php +++ b/src/Languages/Base/Injections/GutterInjection.php @@ -5,10 +5,10 @@ namespace Tempest\Highlight\Languages\Base\Injections; use Tempest\Highlight\Escape; -use Tempest\Highlight\TerminalTheme; use Tempest\Highlight\Highlighter; use Tempest\Highlight\Injection; use Tempest\Highlight\ParsedInjection; +use Tempest\Highlight\TerminalTheme; final class GutterInjection implements Injection { From a3b207929d728bd8c29c16f4c1a089ceccb3211c Mon Sep 17 00:00:00 2001 From: Nima HeydariNasab Date: Fri, 30 Aug 2024 11:06:27 +0330 Subject: [PATCH 5/5] Refactor gutter injection --- src/Languages/Base/Injections/GutterInjection.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Languages/Base/Injections/GutterInjection.php b/src/Languages/Base/Injections/GutterInjection.php index 4fb4468..e84adb2 100644 --- a/src/Languages/Base/Injections/GutterInjection.php +++ b/src/Languages/Base/Injections/GutterInjection.php @@ -63,13 +63,14 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio $gutterClass = 'hl-gutter' . ($hasClasses ? ' ' . $hasClasses : ''); $lines[$i] = sprintf( - Escape::tokens('%s'.($highlighter->getTheme() instanceof TerminalTheme ? ' ' : '').'%s'), + Escape::tokens('%s%s%s'), $gutterClass, str_pad( string: (string) $gutterNumber, length: $gutterWidth, pad_type: STR_PAD_LEFT, ), + $highlighter->getTheme() instanceof TerminalTheme ? ' ' : '', $line, ); }