Skip to content

Commit cc971a9

Browse files
authored
feat: yfm plugins parameter (#143)
1 parent 7a8f1b9 commit cc971a9

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/data/transformPageContent.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {MarkdownItPluginCb} from '@doc-tools/transform/lib/plugins/typings';
12
import {ConstructorBlock, PageContent} from '@gravity-ui/page-constructor';
23
import {contentTransformer} from '@gravity-ui/page-constructor/server';
34
import yaml from 'js-yaml';
@@ -16,15 +17,17 @@ type TransformPageContentPropsType = {
1617
lang: Lang;
1718
region?: string;
1819
typographyConfig?: TypographyConfigType;
20+
plugins?: MarkdownItPluginCb[];
1921
};
2022

2123
type TransformBlocksPropsType = {
2224
blocks: ConstructorBlock[];
2325
lang: Lang;
2426
typographyConfig?: TypographyConfigType;
27+
plugins?: MarkdownItPluginCb[];
2528
};
2629

27-
const transformer = ({blocks, lang, typographyConfig}: TransformBlocksPropsType) =>
30+
const transformer = ({blocks, lang, typographyConfig, plugins}: TransformBlocksPropsType) =>
2831
contentTransformer({
2932
content: {
3033
blocks: blocks || [],
@@ -35,6 +38,7 @@ const transformer = ({blocks, lang, typographyConfig}: TransformBlocksPropsType)
3538
...typographyConfig,
3639
...getExtendTypographyConfig(),
3740
},
41+
plugins,
3842
},
3943
});
4044

@@ -45,13 +49,15 @@ const transformer = ({blocks, lang, typographyConfig}: TransformBlocksPropsType)
4549
* @param lang - runtime app lang
4650
* @param region - runtime app region
4751
* @param typographyConfig - page-constructor extend typography config
52+
* @param plugins - YFM plugins
4853
* @returns transformed content
4954
*/
5055
export const transformPageContent = ({
5156
content,
5257
lang,
5358
region,
5459
typographyConfig = {},
60+
plugins,
5561
}: TransformPageContentPropsType) => {
5662
try {
5763
const transformedContent = filterContent(yaml.load(content) as PageContent, {lang, region});
@@ -61,6 +67,7 @@ export const transformPageContent = ({
6167
blocks: transformedContent.blocks,
6268
lang,
6369
typographyConfig,
70+
plugins,
6471
});
6572

6673
transformedContent.blocks = transformedBlocks;

src/data/transformPost.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {typografToHTML, typografToText, yfmTransformer} from '@gravity-ui/page-constructor/server';
22

3-
import {PostData} from '../models/common';
3+
import {PostData, TransformPostOptions} from '../models/common';
44
import {Lang} from '../models/locale';
55

66
/**
@@ -9,9 +9,14 @@ import {Lang} from '../models/locale';
99
* @param postData - post data
1010
* @param lang - runtime language
1111
*
12+
* @param plugins - YFM plugins list
1213
* @returns -prepared post
1314
*/
14-
export const transformPost = (postData: PostData, lang: Lang) => {
15+
export const transformPost = (
16+
postData: PostData,
17+
lang: Lang,
18+
{plugins}: TransformPostOptions = {},
19+
) => {
1520
if (!postData) {
1621
// eslint-disable-next-line no-console
1722
console.error('Post not found');
@@ -28,6 +33,6 @@ export const transformPost = (postData: PostData, lang: Lang) => {
2833
textTitle: typografToText(title, lang),
2934
htmlTitle: typografToHTML(title, lang),
3035
metaTitle: metaTitle || title,
31-
description: yfmTransformer(lang, description as string),
36+
description: yfmTransformer(lang, description as string, {plugins}),
3237
};
3338
};

src/models/common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {ReactNode} from 'react';
22

3+
import {MarkdownItPluginCb} from '@doc-tools/transform/lib/plugins/typings';
34
import {HeaderBlockProps as PageConstructorHeaderBlockProps} from '@gravity-ui/page-constructor';
45
import {IBrowser, IDevice} from 'ua-parser-js';
56

@@ -211,3 +212,7 @@ export enum PostCardTitleHeadingLevel {
211212
H2 = 'h2',
212213
H3 = 'h3',
213214
}
215+
216+
export interface TransformPostOptions {
217+
plugins?: MarkdownItPluginCb[];
218+
}

0 commit comments

Comments
 (0)