Skip to content

Commit 8ea2585

Browse files
committed
feat: Support inline rendering
1 parent 7ea26d7 commit 8ea2585

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

packages/poml/presentation.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ export namespace Serialize {
421421
* if it's unnamed.
422422
*/
423423
export const Environment = component('Serialize.Environment')((
424-
props: React.PropsWithChildren<PropsSerializeBase>
424+
props: React.PropsWithChildren<PropsSerializeBase & InlineProps>
425425
) => {
426426
const parentPresentation = React.useContext(PresentationApproach);
427427

@@ -435,6 +435,7 @@ export namespace Serialize {
435435
originalEndIndex,
436436
writerOptions,
437437
sourcePath,
438+
inline,
438439
...others
439440
} = props;
440441

@@ -475,9 +476,9 @@ export namespace Serialize {
475476
);
476477
if (parentPresentation?.presentation === 'markup') {
477478
// If the parent is in markup mode, we need a wrapper (e.g., ```json...```).
478-
// TODO: support inline = true
479+
// Support inline rendering when requested; default remains block fence.
479480
elem = (
480-
<Markup.EncloseSerialize inline={false} lang={serializer} {...others}>
481+
<Markup.EncloseSerialize inline={inline ?? false} lang={serializer} {...others}>
481482
{elem}
482483
</Markup.EncloseSerialize>
483484
);
@@ -552,7 +553,7 @@ export namespace Free {
552553
* which will be kept as is without any processing.
553554
*/
554555
export const Environment = component('Free.Environment')((
555-
props: React.PropsWithChildren<PropsFreeBase>
556+
props: React.PropsWithChildren<PropsFreeBase & InlineProps>
556557
) => {
557558
const parentPresentation = React.useContext(PresentationApproach);
558559

@@ -566,6 +567,7 @@ export namespace Free {
566567
writerOptions,
567568
sourcePath,
568569
whiteSpace = 'pre',
570+
inline,
569571
...others
570572
} = props;
571573

@@ -589,9 +591,9 @@ export namespace Free {
589591
);
590592
if (parentPresentation?.presentation === 'markup') {
591593
// If the parent is in markup mode, we need a wrapper (e.g., ```...```).
592-
// TODO: support inline = true
594+
// Support inline rendering when requested; default remains block fence.
593595
elem = (
594-
<Markup.EncloseSerialize inline={false} {...others}>
596+
<Markup.EncloseSerialize inline={inline ?? false} {...others}>
595597
{elem}
596598
</Markup.EncloseSerialize>
597599
);

packages/poml/tests/presentation.test.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ describe('markdown json hybrid', () => {
5252
);
5353
});
5454

55+
test('envInline', async () => {
56+
const env = (
57+
<Markup.Environment>
58+
<Serialize.Environment inline={true}>
59+
<Serialize.Any name="hello">world</Serialize.Any>
60+
</Serialize.Environment>
61+
</Markup.Environment>
62+
);
63+
expect(await read(env)).toBe(
64+
'<env presentation="markup" markup-lang="markdown"><code inline="true" lang="json"><env presentation="serialize" serializer="json"><any name="hello">world</any></env></code></env>'
65+
);
66+
});
67+
5568
test('jsonMarkdown', async () => {
5669
const env = (
5770
<Serialize.Environment>
@@ -74,6 +87,19 @@ describe('free', () => {
7487

7588
test('freeText', async () => {
7689
const text = <Free.Text>{'hello\nworld'}</Free.Text>;
77-
expect(await read(text)).toBe('<env presentation="free" white-space="pre"><text white-space="pre">hello\nworld</text></env>');
90+
expect(await read(text)).toBe(
91+
'<env presentation="free" white-space="pre"><text white-space="pre">hello\nworld</text></env>'
92+
);
93+
});
94+
95+
test('freeInlineInMarkup', async () => {
96+
const env = (
97+
<Markup.Environment>
98+
<Free.Environment inline={true}>hello</Free.Environment>
99+
</Markup.Environment>
100+
);
101+
expect(await read(env)).toBe(
102+
'<env presentation="markup" markup-lang="markdown"><code inline="true"><env presentation="free" white-space="pre">hello</env></code></env>'
103+
);
78104
});
79105
});

0 commit comments

Comments
 (0)