Skip to content

Commit f4383b1

Browse files
committed
WIP
1 parent cd20e38 commit f4383b1

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

src/BuildCommand.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
5353
$pdf = (new Book($config))
5454
->withCover($this->cover($currentPath, $config))
5555
->withCover($this->cover($currentPath, $config, 'cover-back'))
56-
->withColophon(file_get_contents($currentPath .'/assets/colophon.html'))
56+
->withColophon(file_get_contents($currentPath.'/assets/colophon.html'))
5757
->withTheme($theme)
5858
->withTitle($config['title'])
5959
->withAuthor($config['author'])
@@ -80,11 +80,19 @@ public function execute(InputInterface $input, OutputInterface $output): int
8080

8181
$output->writeln('<fg=yellow>==></> Writing PDF To Disk ...');
8282
$output->writeln('');
83+
8384
$output->writeln('✨✨ '.$pdf->getPageCount().' PDF pages ✨✨');
8485

85-
$pdf->Output(
86-
sprintf('%s/export/%s.pdf', $currentPath, $config['title'])
87-
);
86+
$pdfFilePath = sprintf('%s/export/%s.pdf', $currentPath, $config['title']);
87+
$pdf->Output($pdfFilePath);
88+
89+
// Создаем кликабельную ссылку для поддерживающих терминалов
90+
$output->writeln('✨✨ '.$pdf->getPageCount().' PDF pages ✨✨');
91+
$output->writeln(sprintf(
92+
'<href=file://%s>📄 Click to open: %s</>',
93+
$pdfFilePath,
94+
$pdfFilePath
95+
));
8896

8997
$output->writeln('<info>Book Built Successfully!</info>');
9098

@@ -117,8 +125,8 @@ protected function ensureExportDirectoryExists(string $currentPath): void
117125
*/
118126
protected function cover(string $currentPath, array $config, string $filename = 'cover'): string
119127
{
120-
$jpgPath = $currentPath . '/assets/' . $filename . '.jpg';
121-
$htmlPath = $currentPath . '/assets/' . $filename . '.html';
128+
$jpgPath = $currentPath.'/assets/'.$filename.'.jpg';
129+
$htmlPath = $currentPath.'/assets/'.$filename.'.html';
122130

123131
if ($this->disk->isFile($jpgPath)) {
124132
$coverPosition = $config['cover']['position'] ?? 'position: absolute; left:0; right: 0; top: -.2; bottom: 0;';
@@ -138,7 +146,6 @@ protected function cover(string $currentPath, array $config, string $filename =
138146
return '';
139147
}
140148

141-
142149
/**
143150
* @param $currentPath
144151
* @param string $themeName

src/MarkdownProcessor.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public function __construct()
3030
$environment->addExtension(new GithubFlavoredMarkdownExtension());
3131
$environment->addExtension(new TaskListExtension());
3232

33-
//$environment->addExtension(new PhikiExtension(Theme::GithubLight));
33+
// $environment->addExtension(new PhikiExtension(Theme::GithubLight));
3434

35-
$highlighter = new Highlighter(new InlineTheme(__DIR__ . '/../assets/hightlight.css'));
35+
$highlighter = new Highlighter(new InlineTheme(__DIR__.'/../assets/hightlight.css'));
3636
$environment->addExtension(new HighlightExtension($highlighter));
3737

3838
/*
@@ -62,8 +62,7 @@ public function convert(string $markdown, int $index): string
6262
'Trademark',
6363
]);
6464

65-
$fixer->setLocale("ru");
66-
65+
$fixer->setLocale('ru');
6766

6867
$crawler = new Crawler($html);
6968

@@ -81,10 +80,9 @@ public function convert(string $markdown, int $index): string
8180
$html = $t->apply($html);
8281
});
8382

84-
8583
$crawler
8684
->filter('p,li')
87-
->each(function (Crawler $elm) use ($fixer, &$html) {
85+
->each(function (Crawler $elm) use (&$html) {
8886

8987
$content = $elm->html();
9088

@@ -93,8 +91,6 @@ public function convert(string $markdown, int $index): string
9391
$html = Str::of($html)->replace($content, $paragraph);
9492
});
9593

96-
97-
9894
$syllable = new Syllable('ru');
9995
$syllable->setCache(null);
10096
$syllable->setMinWordLength(2);
@@ -107,11 +103,12 @@ public function convert(string $markdown, int $index): string
107103

108104
}
109105

110-
protected function preventShortWordOrphans(string $text, int $maxLength = 2): string {
106+
protected function preventShortWordOrphans(string $text, int $maxLength = 2): string
107+
{
111108
// Регулярка ищет слова длиной <= maxLength перед пробелом или переносом строки
112109
// \b — граница слова, \w{1,maxLength} — слово длиной 1 до maxLength букв
113110
// \s+ — пробелы после слова
114-
$pattern = '/\b(\w{1,' . $maxLength . '})\s+/u';
111+
$pattern = '/\b(\w{1,'.$maxLength.'})\s+/u';
115112

116113
// Заменяем пробелы на неразрывный пробел
117114
$replacement = '$1&nbsp;';

0 commit comments

Comments
 (0)