Skip to content

Commit c86caaf

Browse files
Jaakko Heusalathejhh
authored andcommitted
Fixed code blocks from rune content
1 parent 056e6f3 commit c86caaf

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/views/products/ProductContentRenderer.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import { UnfoldableCard as UnfoldableCard2 } from "../../components/UnfoldableCa
2020
import { parseOperatingSystem } from "../../hook/helpers/getOperatingSystem";
2121
import { I18N_CONTENT_SERVICE_NS_PREFIX } from "../../i18n";
2222
import { DOWNLOAD_OPTIONS_SERVICE } from "./ContentService";
23-
import { isArray } from "./helpers/isArray";
23+
import {
24+
isArray,
25+
isArrayOf,
26+
} from "./helpers/isArray";
2427
import { isString } from "./helpers/isString";
2528
import { RendererContext } from "./RendererContextImpl";
2629
import { isBaseContent } from "./types/BaseContent";
@@ -35,7 +38,9 @@ import {
3538
} from "./types/CardContent";
3639
import { isComponentContent } from "./types/ComponentContent";
3740
import { Content } from "./types/Content";
38-
import { ContentType } from "./types/ContentType";
41+
import {
42+
ContentType,
43+
} from "./types/ContentType";
3944
import { isDropdownOsSelectorContent } from "./types/DropdownOsSelectorContent";
4045
import { isFoldableCardContent } from "./types/FoldableCardContent";
4146
import {
@@ -224,6 +229,8 @@ export class ProductContentRenderer {
224229
h3: <h3 />,
225230
h4: <h4 />,
226231
h5: <h5 />,
232+
code: <code />,
233+
pre: <pre />,
227234
h6: <h6 />,
228235
a: <a />,
229236
span: <span />,
@@ -470,6 +477,23 @@ export class ProductContentRenderer {
470477
}
471478

472479
if (content?.type === ContentType.CODE) {
480+
const body = content.body;
481+
if (isArrayOf<Content>(body)) {
482+
return (
483+
<code className={this.prepareClassName(content.classes, context)}>
484+
{body.map((item: Content) : ReactNode => {
485+
if (isString(item)) {
486+
return <>{item}</>;
487+
}
488+
return <>{this.render(item, context)}</>;
489+
})}
490+
</code>
491+
)
492+
}
493+
494+
if (isString(content?.body)) {
495+
return <code className={this.prepareClassName(content.classes, context)}>{content?.body}</code>
496+
}
473497
return <code className={this.prepareClassName(content.classes, context)}>{this.render(content?.body, context)}</code>
474498
}
475499

src/views/products/helpers/isArray.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export function isArray (value: unknown): value is unknown[] {
77
);
88
}
99

10+
export function isArrayOf<T> (value: unknown): value is T[] {
11+
return isArray(value);
12+
}
13+
1014
export function isArrayOrUndefined (value: unknown): value is string | undefined {
1115
return value === undefined || isArray(value);
1216
}

0 commit comments

Comments
 (0)