Skip to content

Commit 3dd4a6d

Browse files
authored
Merge pull request #372 from herndlm/fix-large-inline-image
Support larger inline images
2 parents c76487c + c4642db commit 3dd4a6d

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/Formatter/MarkdownToHtml.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Psr\Log\LoggerInterface;
99
use Roave\DocbookTool\DocbookPage;
1010

11+
use function ini_set;
1112
use function sprintf;
1213

1314
final class MarkdownToHtml implements PageFormatter
@@ -18,6 +19,11 @@ public function __construct(private readonly LoggerInterface $logger)
1819
{
1920
$this->markdownParser = new MarkdownExtra();
2021
$this->markdownParser->code_class_prefix = 'lang-';
22+
23+
// The PCRE backtrack_limit is increased to support bigger inline content, e.g. images
24+
// See https://github.com/michelf/php-markdown/issues/399 and https://github.com/michelf/php-markdown/issues/399
25+
// 5_000_000 is 5-times the default and should allow images up to at least 1 MB
26+
ini_set('pcre.backtrack_limit', 5_000_000);
2127
}
2228

2329
public function __invoke(DocbookPage $page): DocbookPage
535 KB
Loading

test/fixture/docbook/test.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ Here are some images:
6363

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

66+
### A larger image
67+
68+
This is an image that's over 500kb so we can be sure that bigger images work:
69+
70+
![A snowy mountain](./large-image.jpeg)
71+
6672
## Inline PUML file
6773

6874
![An external PlantUML diagram](./external-diagram.puml)

test/fixture/expectations/out.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ <h2>Some images</h2>
8585

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

88+
<h3>A larger image</h3>
89+
90+
<p>This is an image that's over 500kb so we can be sure that bigger images work:</p>
91+
92+
<p><img src="data:image/jpeg;base64,/9j/4A%s" alt="A snowy mountain" /></p>
93+
8894
<h2>Inline PUML file</h2>
8995

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

0 commit comments

Comments
 (0)