Skip to content

feat: yfm plugins parameter #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = {},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need use agrument-object when arguments quantity more than 2, but it is breaking change. I suggest after merge of this PR to make edits in #137. can you create issue after merge this PR ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course

) => {
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[];
}