From c1bd8b8e5e16866a80e0c7268b56e585846557af Mon Sep 17 00:00:00 2001 From: Roberto Butti Date: Tue, 3 Sep 2024 23:38:09 +0200 Subject: [PATCH 1/2] Markdown Attributes Syntax --- CHANGELOG.md | 6 +++++- readme.md | 30 ++++++++++++++++++++++++++++++ src/Commands/BaseBuildCommand.php | 3 +++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6861116..bee627b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.1.2 - 3rd September 2024 +- Adding Markdown custom extension for managing attributes (like CSS class) +- Updating dependencies + ## 1.1.1 - 24th Aug 2024 - Updating dependencies - Updating some styles/fonts for Headings @@ -77,4 +81,4 @@ - using Pint with PSR12 - added configuration for cover image (instead of using hard-coded cover.jpg, you can specify a new file name and format, for example, my-cover.png) - added the header config for the CSS style for the page header -- added the front matter capabilities (the title front matter option will be used for the page header). \ No newline at end of file +- added the front matter capabilities (the title front matter option will be used for the page header). diff --git a/readme.md b/readme.md index be18417..c4221ab 100644 --- a/readme.md +++ b/readme.md @@ -256,6 +256,36 @@ This is an example. Edit your `/ibis.php` configuration files to define the font files to be loaded from the `/assets/fonts` directory. Afterward, you may use the defined fonts in your themes (`/assets/theme-light.html` & `/assets/theme-dark.html`). +### Setting the Attributes + +Considering that the process of converting Markdown to PDF involves generating HTML, you can apply CSS styles to set specific class styles. +To add a CSS class (or any attribute) to an element in Markdown, you can use attribute syntax. + +For example, to add a CSS class to an image, consider that the conversion from Markdown results in an HTML `p` element containing an `img` element. +You can define a CSS style like this: + +```css +.image-container { + text-align: center; /* Center the content inside the paragraph */ + padding: 20px; /* Optional: Add padding around the paragraph */ + background-color: #f5f5f5; /* Optional: Set a background color */ + border-radius: 10px; /* Optional: Add rounded corners */ +} + +.image-container img { + max-width: 80vw; /* Set the image to 80% of the viewport width */ + height: auto; /* Maintain the aspect ratio */ + display: inline-block; /* Ensure the image behaves like an inline-block element */ +} +``` + +Then, when you need to embed an image in Markdown using the image-container CSS class, you can use the following syntax: + +```md +{#id-cover-001 .image-container} +![Ibis Next Cover Image](./content/images/ibis-next-cover.png) +``` + ## Generating eBook diff --git a/src/Commands/BaseBuildCommand.php b/src/Commands/BaseBuildCommand.php index a96e070..f0c448e 100644 --- a/src/Commands/BaseBuildCommand.php +++ b/src/Commands/BaseBuildCommand.php @@ -6,6 +6,7 @@ use Ibis\Markdown\Extensions\Aside; use Ibis\Markdown\Extensions\AsideExtension; use Ibis\Markdown\Extensions\AsideRenderer; +use League\CommonMark\Extension\Attributes\AttributesExtension; use SplFileInfo; use Illuminate\Filesystem\Filesystem; @@ -75,6 +76,8 @@ protected function buildHtml(string $path, array $config): Collection $environment->addExtension(new TableExtension()); $environment->addExtension(new FrontMatterExtension()); $environment->addExtension(new AsideExtension()); + $environment->addExtension(new AttributesExtension()); + $environment->addRenderer(FencedCode::class, new FencedCodeRenderer([ 'html', 'php', 'js', 'bash', 'json', From e60551aa3e75bc3071c7b31c66171b518a9bef5e Mon Sep 17 00:00:00 2001 From: Roberto Butti Date: Tue, 3 Sep 2024 23:41:05 +0200 Subject: [PATCH 2/2] Fix style with new cs rules --- composer.lock | 82 +++++++++++++++---------------- src/Commands/BaseBuildCommand.php | 2 - src/Commands/BuildEpubCommand.php | 1 - src/Commands/BuildHtmlCommand.php | 1 - src/Commands/BuildPdfCommand.php | 3 -- 5 files changed, 41 insertions(+), 48 deletions(-) diff --git a/composer.lock b/composer.lock index 618a89e..c7be0ef 100644 --- a/composer.lock +++ b/composer.lock @@ -526,16 +526,16 @@ }, { "name": "illuminate/collections", - "version": "v11.21.0", + "version": "v11.22.0", "source": { "type": "git", "url": "https://github.com/illuminate/collections.git", - "reference": "d373c9f382f38dc5e612dbe1cd196b154cd1063c" + "reference": "66d2c9bdf5641599735d402c1c504b54734a9cca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/collections/zipball/d373c9f382f38dc5e612dbe1cd196b154cd1063c", - "reference": "d373c9f382f38dc5e612dbe1cd196b154cd1063c", + "url": "https://api.github.com/repos/illuminate/collections/zipball/66d2c9bdf5641599735d402c1c504b54734a9cca", + "reference": "66d2c9bdf5641599735d402c1c504b54734a9cca", "shasum": "" }, "require": { @@ -577,11 +577,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-08-19T02:05:39+00:00" + "time": "2024-08-23T18:49:36+00:00" }, { "name": "illuminate/conditionable", - "version": "v11.21.0", + "version": "v11.22.0", "source": { "type": "git", "url": "https://github.com/illuminate/conditionable.git", @@ -627,16 +627,16 @@ }, { "name": "illuminate/contracts", - "version": "v11.21.0", + "version": "v11.22.0", "source": { "type": "git", "url": "https://github.com/illuminate/contracts.git", - "reference": "34ead9385e0eab7e947807d77da66faf9bdf95ff" + "reference": "af9b459f195d57f279ec30a45446ddaeb3337bcb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/contracts/zipball/34ead9385e0eab7e947807d77da66faf9bdf95ff", - "reference": "34ead9385e0eab7e947807d77da66faf9bdf95ff", + "url": "https://api.github.com/repos/illuminate/contracts/zipball/af9b459f195d57f279ec30a45446ddaeb3337bcb", + "reference": "af9b459f195d57f279ec30a45446ddaeb3337bcb", "shasum": "" }, "require": { @@ -671,20 +671,20 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-08-01T19:08:33+00:00" + "time": "2024-08-21T16:02:16+00:00" }, { "name": "illuminate/filesystem", - "version": "v11.21.0", + "version": "v11.22.0", "source": { "type": "git", "url": "https://github.com/illuminate/filesystem.git", - "reference": "43b8d2af61dd6ca882e192fa4ca803d2294d4507" + "reference": "7e44057ac57635465c91c3fc6247c5d87bd1feed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/filesystem/zipball/43b8d2af61dd6ca882e192fa4ca803d2294d4507", - "reference": "43b8d2af61dd6ca882e192fa4ca803d2294d4507", + "url": "https://api.github.com/repos/illuminate/filesystem/zipball/7e44057ac57635465c91c3fc6247c5d87bd1feed", + "reference": "7e44057ac57635465c91c3fc6247c5d87bd1feed", "shasum": "" }, "require": { @@ -738,11 +738,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-06-28T20:10:30+00:00" + "time": "2024-09-03T13:20:49+00:00" }, { "name": "illuminate/macroable", - "version": "v11.21.0", + "version": "v11.22.0", "source": { "type": "git", "url": "https://github.com/illuminate/macroable.git", @@ -788,16 +788,16 @@ }, { "name": "illuminate/support", - "version": "v11.21.0", + "version": "v11.22.0", "source": { "type": "git", "url": "https://github.com/illuminate/support.git", - "reference": "82e493e7b9bb94d1b065260170e3ecbfd3670126" + "reference": "51efc0516526413b4be641a1731d15d4394de2ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/82e493e7b9bb94d1b065260170e3ecbfd3670126", - "reference": "82e493e7b9bb94d1b065260170e3ecbfd3670126", + "url": "https://api.github.com/repos/illuminate/support/zipball/51efc0516526413b4be641a1731d15d4394de2ff", + "reference": "51efc0516526413b4be641a1731d15d4394de2ff", "shasum": "" }, "require": { @@ -858,7 +858,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-08-20T14:50:34+00:00" + "time": "2024-09-03T13:21:20+00:00" }, { "name": "league/commonmark", @@ -2102,16 +2102,16 @@ }, { "name": "setasign/fpdi", - "version": "v2.6.0", + "version": "v2.6.1", "source": { "type": "git", "url": "https://github.com/Setasign/FPDI.git", - "reference": "a6db878129ec6c7e141316ee71872923e7f1b7ad" + "reference": "09a816004fcee9ed3405bd164147e3fdbb79a56f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Setasign/FPDI/zipball/a6db878129ec6c7e141316ee71872923e7f1b7ad", - "reference": "a6db878129ec6c7e141316ee71872923e7f1b7ad", + "url": "https://api.github.com/repos/Setasign/FPDI/zipball/09a816004fcee9ed3405bd164147e3fdbb79a56f", + "reference": "09a816004fcee9ed3405bd164147e3fdbb79a56f", "shasum": "" }, "require": { @@ -2162,7 +2162,7 @@ ], "support": { "issues": "https://github.com/Setasign/FPDI/issues", - "source": "https://github.com/Setasign/FPDI/tree/v2.6.0" + "source": "https://github.com/Setasign/FPDI/tree/v2.6.1" }, "funding": [ { @@ -2170,7 +2170,7 @@ "type": "tidelift" } ], - "time": "2023-12-11T16:03:32+00:00" + "time": "2024-09-02T10:17:15+00:00" }, { "name": "spatie/commonmark-highlighter", @@ -3821,16 +3821,16 @@ }, { "name": "laravel/pint", - "version": "v1.17.2", + "version": "v1.17.3", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "e8a88130a25e3f9d4d5785e6a1afca98268ab110" + "reference": "9d77be916e145864f10788bb94531d03e1f7b482" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/e8a88130a25e3f9d4d5785e6a1afca98268ab110", - "reference": "e8a88130a25e3f9d4d5785e6a1afca98268ab110", + "url": "https://api.github.com/repos/laravel/pint/zipball/9d77be916e145864f10788bb94531d03e1f7b482", + "reference": "9d77be916e145864f10788bb94531d03e1f7b482", "shasum": "" }, "require": { @@ -3841,13 +3841,13 @@ "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.61.1", - "illuminate/view": "^10.48.18", + "friendsofphp/php-cs-fixer": "^3.64.0", + "illuminate/view": "^10.48.20", "larastan/larastan": "^2.9.8", "laravel-zero/framework": "^10.4.0", "mockery/mockery": "^1.6.12", "nunomaduro/termwind": "^1.15.1", - "pestphp/pest": "^2.35.0" + "pestphp/pest": "^2.35.1" }, "bin": [ "builds/pint" @@ -3883,7 +3883,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-08-06T15:11:54+00:00" + "time": "2024-09-03T15:00:28+00:00" }, { "name": "nikic/php-parser", @@ -4719,16 +4719,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.0", + "version": "1.12.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "384af967d35b2162f69526c7276acadce534d0e1" + "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/384af967d35b2162f69526c7276acadce534d0e1", - "reference": "384af967d35b2162f69526c7276acadce534d0e1", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", + "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", "shasum": "" }, "require": { @@ -4773,7 +4773,7 @@ "type": "github" } ], - "time": "2024-08-27T09:18:05+00:00" + "time": "2024-09-03T19:55:22+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/src/Commands/BaseBuildCommand.php b/src/Commands/BaseBuildCommand.php index f0c448e..9fe8cf6 100644 --- a/src/Commands/BaseBuildCommand.php +++ b/src/Commands/BaseBuildCommand.php @@ -8,7 +8,6 @@ use Ibis\Markdown\Extensions\AsideRenderer; use League\CommonMark\Extension\Attributes\AttributesExtension; use SplFileInfo; - use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Arr; use Illuminate\Support\Collection; @@ -20,7 +19,6 @@ use League\CommonMark\Extension\FrontMatter\FrontMatterExtension; use League\CommonMark\Extension\GithubFlavoredMarkdownExtension; use League\CommonMark\Extension\Table\TableExtension; - use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode; use League\CommonMark\Extension\CommonMark\Node\Block\IndentedCode; use League\CommonMark\Extension\FrontMatter\Output\RenderedContentWithFrontMatter; diff --git a/src/Commands/BuildEpubCommand.php b/src/Commands/BuildEpubCommand.php index 4a4c073..43267a4 100644 --- a/src/Commands/BuildEpubCommand.php +++ b/src/Commands/BuildEpubCommand.php @@ -6,7 +6,6 @@ use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Support\Arr; use Illuminate\Support\Collection; - use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use PHPePub\Core\EPub; diff --git a/src/Commands/BuildHtmlCommand.php b/src/Commands/BuildHtmlCommand.php index 717163e..8430793 100644 --- a/src/Commands/BuildHtmlCommand.php +++ b/src/Commands/BuildHtmlCommand.php @@ -5,7 +5,6 @@ use Ibis\Config; use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Support\Collection; - use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Command\Command; diff --git a/src/Commands/BuildPdfCommand.php b/src/Commands/BuildPdfCommand.php index 9c11dd9..23e876e 100644 --- a/src/Commands/BuildPdfCommand.php +++ b/src/Commands/BuildPdfCommand.php @@ -3,11 +3,8 @@ namespace Ibis\Commands; use Mpdf\Mpdf; - use Mpdf\Config\FontVariables; use Mpdf\Config\ConfigVariables; - - use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Symfony\Component\Console\Command\Command;