Skip to content

Commit

Permalink
feat: yfm plugins parameter (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyzyl-ool authored Oct 30, 2023
1 parent 7a8f1b9 commit cc971a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/data/transformPageContent.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {MarkdownItPluginCb} from '@doc-tools/transform/lib/plugins/typings';
import {ConstructorBlock, PageContent} from '@gravity-ui/page-constructor';
import {contentTransformer} from '@gravity-ui/page-constructor/server';
import yaml from 'js-yaml';
Expand All @@ -16,15 +17,17 @@ type TransformPageContentPropsType = {
lang: Lang;
region?: string;
typographyConfig?: TypographyConfigType;
plugins?: MarkdownItPluginCb[];
};

type TransformBlocksPropsType = {
blocks: ConstructorBlock[];
lang: Lang;
typographyConfig?: TypographyConfigType;
plugins?: MarkdownItPluginCb[];
};

const transformer = ({blocks, lang, typographyConfig}: TransformBlocksPropsType) =>
const transformer = ({blocks, lang, typographyConfig, plugins}: TransformBlocksPropsType) =>
contentTransformer({
content: {
blocks: blocks || [],
Expand All @@ -35,6 +38,7 @@ const transformer = ({blocks, lang, typographyConfig}: TransformBlocksPropsType)
...typographyConfig,
...getExtendTypographyConfig(),
},
plugins,
},
});

Expand All @@ -45,13 +49,15 @@ const transformer = ({blocks, lang, typographyConfig}: TransformBlocksPropsType)
* @param lang - runtime app lang
* @param region - runtime app region
* @param typographyConfig - page-constructor extend typography config
* @param plugins - YFM plugins
* @returns transformed content
*/
export const transformPageContent = ({
content,
lang,
region,
typographyConfig = {},
plugins,
}: TransformPageContentPropsType) => {
try {
const transformedContent = filterContent(yaml.load(content) as PageContent, {lang, region});
Expand All @@ -61,6 +67,7 @@ export const transformPageContent = ({
blocks: transformedContent.blocks,
lang,
typographyConfig,
plugins,
});

transformedContent.blocks = transformedBlocks;
Expand Down
11 changes: 8 additions & 3 deletions src/data/transformPost.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {typografToHTML, typografToText, yfmTransformer} from '@gravity-ui/page-constructor/server';

import {PostData} from '../models/common';
import {PostData, TransformPostOptions} from '../models/common';
import {Lang} from '../models/locale';

/**
Expand All @@ -9,9 +9,14 @@ import {Lang} from '../models/locale';
* @param postData - post data
* @param lang - runtime language
*
* @param plugins - YFM plugins list
* @returns -prepared post
*/
export const transformPost = (postData: PostData, lang: Lang) => {
export const transformPost = (
postData: PostData,
lang: Lang,
{plugins}: TransformPostOptions = {},
) => {
if (!postData) {
// eslint-disable-next-line no-console
console.error('Post not found');
Expand All @@ -28,6 +33,6 @@ export const transformPost = (postData: PostData, lang: Lang) => {
textTitle: typografToText(title, lang),
htmlTitle: typografToHTML(title, lang),
metaTitle: metaTitle || title,
description: yfmTransformer(lang, description as string),
description: yfmTransformer(lang, description as string, {plugins}),
};
};
5 changes: 5 additions & 0 deletions src/models/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {ReactNode} from 'react';

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

Expand Down Expand Up @@ -211,3 +212,7 @@ export enum PostCardTitleHeadingLevel {
H2 = 'h2',
H3 = 'h3',
}

export interface TransformPostOptions {
plugins?: MarkdownItPluginCb[];
}

0 comments on commit cc971a9

Please sign in to comment.