Skip to content

Commit 53dd80e

Browse files
authored
Merge branch 'master' into compile-tailwindcss
2 parents 9f5c930 + 94926a6 commit 53dd80e

File tree

8 files changed

+165
-56
lines changed

8 files changed

+165
-56
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ This serves two purposes:
1010
2. At release time, you can move the Unreleased section changes into a new release version section.
1111

1212
### Added
13-
- for new features.
13+
- Added support for using HTML comments to create Markdown code block filepath labels in https://github.com/hydephp/develop/pull/1693
14+
- You can now specify which path to open when using the `--open` option in the serve command in https://github.com/hydephp/develop/pull/1694
1415

1516
### Changed
1617
- After updating a Tailwind minor version, table headers in Typography `.prose` classes are now centered instead of left-aligned by default. See https://github.com/tailwindlabs/tailwindcss-typography/commit/f520c53470630e3ad4d43e3c2306882d33bf5c52

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"watch": "mix watch"
77
},
88
"devDependencies": {
9-
"@tailwindcss/typography": "^0.5.12",
9+
"@tailwindcss/typography": "^0.5.13",
1010
"autoprefixer": "^10.4.19",
1111
"hydefront": "^3.3.0",
1212
"laravel-mix": "^6.0.49",

packages/framework/src/Console/Commands/RouteListCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ public function handle(): int
3232
return Command::SUCCESS;
3333
}
3434

35+
/** @return array<integer, array<string, string>> */
3536
protected function generate(): array
3637
{
37-
return array_map([RouteListItem::class, 'format'], array_values(Hyde::routes()->all()));
38+
return array_map(RouteListItem::format(...), array_values(Hyde::routes()->all()));
3839
}
3940

41+
/** @param array<integer, array<string, string>> $routes */
4042
protected function makeHeader(array $routes): array
4143
{
42-
return array_map([Hyde::class, 'makeTitle'], array_keys($routes[0]));
44+
return array_map(Hyde::makeTitle(...), array_keys($routes[0]));
4345
}
4446
}

packages/framework/src/Console/Commands/ServeCommand.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ServeCommand extends Command
3333
{--dashboard= : Enable the realtime compiler dashboard. (Overrides config setting)}
3434
{--pretty-urls= : Enable pretty URLs. (Overrides config setting)}
3535
{--play-cdn= : Enable the Tailwind Play CDN. (Overrides config setting)}
36-
{--open : Open the site preview in the browser.}
36+
{--open=false : Open the site preview in the browser.}
3737
';
3838

3939
/** @var string */
@@ -46,8 +46,8 @@ public function safeHandle(): int
4646
$this->configureOutput();
4747
$this->printStartMessage();
4848

49-
if ($this->option('open')) {
50-
$this->openInBrowser();
49+
if ($this->option('open') !== 'false') {
50+
$this->openInBrowser((string) $this->option('open'));
5151
}
5252

5353
$this->runServerProcess(sprintf('php -S %s:%d %s',
@@ -143,16 +143,19 @@ protected function checkArgvForOption(string $name): ?string
143143
return null;
144144
}
145145

146-
protected function openInBrowser(): void
146+
protected function openInBrowser(string $path = '/'): void
147147
{
148-
$command = match (PHP_OS_FAMILY) {
148+
$binary = match (PHP_OS_FAMILY) {
149149
'Windows' => 'start',
150150
'Darwin' => 'open',
151151
'Linux' => 'xdg-open',
152152
default => null
153153
};
154154

155-
$process = $command ? Process::command(sprintf('%s http://%s:%d', $command, $this->getHostSelection(), $this->getPortSelection()))->run() : null;
155+
$command = sprintf('%s http://%s:%d', $binary, $this->getHostSelection(), $this->getPortSelection());
156+
$command = rtrim("$command/$path", '/');
157+
158+
$process = $binary ? Process::command($command)->run() : null;
156159

157160
if (! $process || $process->failed()) {
158161
$this->warn('Unable to open the site preview in the browser on your system:');

packages/framework/src/Markdown/Processing/CodeblockFilepathProcessor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Support\Facades\View;
1111
use Illuminate\Support\HtmlString;
1212

13+
use function array_merge;
1314
use function preg_replace;
1415
use function str_contains;
1516
use function str_ireplace;
@@ -36,6 +37,8 @@ class CodeblockFilepathProcessor implements MarkdownPreProcessorContract, Markdo
3637
'/* filepath ',
3738
'# filepath: ',
3839
'# filepath ',
40+
'<!-- filepath: ',
41+
'<!-- filepath ',
3942
];
4043

4144
/**
@@ -52,7 +55,7 @@ public static function preprocess(string $markdown): string
5255
// We then replace these markers in the post-processor.
5356
$lines[$index - 2] .= sprintf(
5457
"\n<!-- HYDE[Filepath]%s -->",
55-
trim(str_ireplace(static::$patterns, '', $line))
58+
trim(str_ireplace(array_merge(static::$patterns, ['-->']), '', $line))
5659
);
5760

5861
// Remove the original comment lines

packages/framework/tests/Feature/Services/Markdown/CodeblockFilepathProcessorTest.php

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function testPreprocessExpandsFilepath()
1717
$markdown = "\n```php\n// filepath: foo.php\necho 'Hello World';\n```";
1818
$expected = "\n<!-- HYDE[Filepath]foo.php -->\n```php\necho 'Hello World';\n```";
1919

20-
$this->assertEquals($expected, CodeblockFilepathProcessor::preprocess($markdown));
20+
$this->assertSame($expected, CodeblockFilepathProcessor::preprocess($markdown));
2121
}
2222

2323
public function testPreprocessAcceptsMultipleFilepathFormats()
@@ -37,7 +37,7 @@ public function testPreprocessAcceptsMultipleFilepathFormats()
3737
$markdown = "\n```php\n{$pattern}foo.php\necho 'Hello World';\n```";
3838
$expected = "\n<!-- HYDE[Filepath]foo.php -->\n```php\necho 'Hello World';\n```";
3939

40-
$this->assertEquals($expected, CodeblockFilepathProcessor::preprocess($markdown));
40+
$this->assertSame($expected, CodeblockFilepathProcessor::preprocess($markdown));
4141
}
4242
}
4343

@@ -54,7 +54,45 @@ public function testFilepathPatternIsCaseInsensitive()
5454
$markdown = "\n```php\n{$pattern}foo.php\necho 'Hello World';\n```";
5555
$expected = "\n<!-- HYDE[Filepath]foo.php -->\n```php\necho 'Hello World';\n```";
5656

57-
$this->assertEquals($expected, CodeblockFilepathProcessor::preprocess($markdown));
57+
$this->assertSame($expected, CodeblockFilepathProcessor::preprocess($markdown));
58+
}
59+
}
60+
61+
public function testPreprocessCanUseHtmlComments()
62+
{
63+
$markdown = <<<'MD'
64+
65+
```html
66+
<!-- filepath: foo.html -->
67+
<p>Hello World</p>
68+
```
69+
MD;
70+
71+
$expected = <<<'MD'
72+
73+
<!-- HYDE[Filepath]foo.html -->
74+
```html
75+
<p>Hello World</p>
76+
```
77+
MD;
78+
79+
$this->assertSame($expected, CodeblockFilepathProcessor::preprocess($markdown));
80+
}
81+
82+
public function testPreprocessCanUseHtmlCommentsWithDifferentPatterns()
83+
{
84+
$patterns = [
85+
'<!-- filepath: ',
86+
'<!-- Filepath: ',
87+
'<!-- FilePath: ',
88+
'<!-- FILEPATH: ',
89+
];
90+
91+
foreach ($patterns as $pattern) {
92+
$markdown = "\n```html\n{$pattern}foo.html\n<p>Hello World</p>\n```";
93+
$expected = "\n<!-- HYDE[Filepath]foo.html -->\n```html\n<p>Hello World</p>\n```";
94+
95+
$this->assertSame($expected, CodeblockFilepathProcessor::preprocess($markdown));
5896
}
5997
}
6098

@@ -72,10 +110,8 @@ public function testPreprocessAcceptsMultipleLanguages()
72110
$markdown = "\n```$language\n// filepath: foo.$language\nfoo\n```";
73111
$expected = "\n<!-- HYDE[Filepath]foo.$language -->\n```$language\nfoo\n```";
74112

75-
$this->assertEquals($expected, CodeblockFilepathProcessor::preprocess($markdown));
113+
$this->assertSame($expected, CodeblockFilepathProcessor::preprocess($markdown));
76114
}
77-
78-
$this->assertEquals($expected, CodeblockFilepathProcessor::preprocess($markdown));
79115
}
80116

81117
public function testPreprocessAcceptsMultipleInputBlocks()

0 commit comments

Comments
 (0)