File tree 6 files changed +148
-3
lines changed 6 files changed +148
-3
lines changed Original file line number Diff line number Diff line change 14
14
"league/commonmark" : " ^2.0" ,
15
15
"symfony/yaml" : " ^2.3 || ^3.0 || ^4.0 || ^5.0 || ^6.0" ,
16
16
"8fold/commonmark-abbreviations" : " ^1.2 || ^2.1" ,
17
- "8fold/commonmark-accessible-heading-permalinks" : " ^1.0"
17
+ "8fold/commonmark-accessible-heading-permalinks" : " ^1.0" ,
18
+ "8fold/commonmark-partials" : " ^1.0"
18
19
},
19
20
"require-dev" : {
20
21
"phpstan/phpstan" : " ^1.2.0" ,
Original file line number Diff line number Diff line change 10
10
use Eightfold \CommonMarkAbbreviations \AbbreviationExtension as Abbreviations ;
11
11
use Eightfold \CommonMarkAccessibleHeadingPermalink \HeadingPermalinkExtension
12
12
as HeadingPermalink ;
13
+ use Eightfold \CommonMarkPartials \PartialsExtension as Partials ;
13
14
14
15
class Markdown extends FluentCommonMark
15
16
{
@@ -74,7 +75,7 @@ public function abbreviations(): Markdown
74
75
}
75
76
76
77
/**
77
- * @param array<string, mixed> $config [description]
78
+ * @param array<string, mixed> $config
78
79
*/
79
80
public function accessibleHeadingPermalinks (array $ config = []): Markdown
80
81
{
@@ -86,4 +87,18 @@ public function accessibleHeadingPermalinks(array $config = []): Markdown
86
87
$ config
87
88
)->addExtension (new HeadingPermalink ());
88
89
}
90
+
91
+ /**
92
+ * @param array<string, mixed> $config
93
+ */
94
+ public function partials (array $ config = []): Markdown
95
+ {
96
+ if (count ($ config ) === 0 ) {
97
+ return $ this ;
98
+ }
99
+ return $ this ->addExtensionWithConfig (
100
+ 'partials ' ,
101
+ $ config
102
+ )->addExtension (new Partials ());
103
+ }
89
104
}
Original file line number Diff line number Diff line change @@ -149,4 +149,43 @@ public function can_use_accessible_heading_permalinks(): void // phpcs:ignore
149
149
150
150
$ this ->assertSame ($ expected , $ result );
151
151
}
152
+
153
+ /**
154
+ * @test
155
+ */
156
+ public function can_use_partials (): void // phpcs: ignore
157
+ {
158
+ $ expected = <<<html
159
+ <p>This was created by a partial</p>
160
+
161
+ html ;
162
+
163
+ $ result = Markdown::create ()->partials ([
164
+ 'partials ' => [
165
+ 'inject ' => 'Eightfold\Markdown\Tests\Mocks\PartialMarkdown '
166
+ ]
167
+ ])->convert (<<<md
168
+ {!! inject !!}
169
+ md
170
+ );
171
+
172
+ $ this ->assertSame ($ expected , $ result );
173
+
174
+ $ expected = <<<html
175
+ <h1>This was created by a partial</h1>
176
+
177
+ html ;
178
+
179
+ $ result = Markdown::create ()->withConfig (['html_input ' => 'allow ' ])
180
+ ->partials ([
181
+ 'partials ' => [
182
+ 'inject ' => 'Eightfold\Markdown\Tests\Mocks\PartialHtml '
183
+ ]
184
+ ])->convert (<<<md
185
+ {!! inject !!}
186
+ md
187
+ );
188
+
189
+ $ this ->assertSame ($ expected , $ result );
190
+ }
152
191
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types=1 );
3
+
4
+ namespace Eightfold \Markdown \Tests \Mocks ;
5
+
6
+ use Eightfold \CommonMarkPartials \PartialInterface ;
7
+
8
+ use Eightfold \CommonMarkPartials \PartialInput ;
9
+
10
+ class PartialHtml implements PartialInterface
11
+ {
12
+ public function __invoke (PartialInput $ input , array $ extras = []): string
13
+ {
14
+ return '<h1>This was created by a partial</h1> ' ;
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ declare (strict_types=1 );
3
+
4
+ namespace Eightfold \Markdown \Tests \Mocks ;
5
+
6
+ use Eightfold \CommonMarkPartials \PartialInterface ;
7
+
8
+ use Eightfold \CommonMarkPartials \PartialInput ;
9
+
10
+ class PartialMarkdown implements PartialInterface
11
+ {
12
+ public function __invoke (PartialInput $ input , array $ extras = []): string
13
+ {
14
+ return 'This was created by a partial ' ;
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments