Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown Attributes Syntax #32

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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).
- added the front matter capabilities (the title front matter option will be used for the page header).
82 changes: 41 additions & 41 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/Commands/BaseBuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
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;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
Expand All @@ -19,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;
Expand Down Expand Up @@ -75,6 +74,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',
Expand Down
1 change: 0 additions & 1 deletion src/Commands/BuildEpubCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/Commands/BuildHtmlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/Commands/BuildPdfCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down