Skip to content

Commit

Permalink
Merge pull request #372 from herndlm/fix-large-inline-image
Browse files Browse the repository at this point in the history
Support larger inline images
  • Loading branch information
Ocramius authored Mar 11, 2024
2 parents c76487c + c4642db commit 3dd4a6d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Formatter/MarkdownToHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Psr\Log\LoggerInterface;
use Roave\DocbookTool\DocbookPage;

use function ini_set;
use function sprintf;

final class MarkdownToHtml implements PageFormatter
Expand All @@ -18,6 +19,11 @@ public function __construct(private readonly LoggerInterface $logger)
{
$this->markdownParser = new MarkdownExtra();
$this->markdownParser->code_class_prefix = 'lang-';

// The PCRE backtrack_limit is increased to support bigger inline content, e.g. images
// See https://github.com/michelf/php-markdown/issues/399 and https://github.com/michelf/php-markdown/issues/399
// 5_000_000 is 5-times the default and should allow images up to at least 1 MB
ini_set('pcre.backtrack_limit', 5_000_000);
}

public function __invoke(DocbookPage $page): DocbookPage
Expand Down
Binary file added test/fixture/docbook/large-image.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions test/fixture/docbook/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ Here are some images:

They are hand drawn, that's why they look rubbish.

### A larger image

This is an image that's over 500kb so we can be sure that bigger images work:

![A snowy mountain](./large-image.jpeg)

## Inline PUML file

![An external PlantUML diagram](./external-diagram.puml)
6 changes: 6 additions & 0 deletions test/fixture/expectations/out.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ <h2>Some images</h2>

<p>They are hand drawn, that's why they look rubbish.</p>

<h3>A larger image</h3>

<p>This is an image that's over 500kb so we can be sure that bigger images work:</p>

<p><img src="data:image/jpeg;base64,/9j/4A%s" alt="A snowy mountain" /></p>

<h2>Inline PUML file</h2>

<p><img src="data:image/png;base64,iVBORw%s" alt="Diagram" /></p>
Expand Down

0 comments on commit 3dd4a6d

Please sign in to comment.