diff --git a/src/text-transform/common.ts b/src/text-transform/common.ts index 2e9fb6ee5..09eff256f 100644 --- a/src/text-transform/common.ts +++ b/src/text-transform/common.ts @@ -11,7 +11,7 @@ export type Transformer = (text: string) => string; export type TransformerRaw = ( lang: Lang, content: string, - additionalPlugins: MarkdownItPluginCb[], + options: {plugins: MarkdownItPluginCb[]}, ) => string; // eslint-disable-next-line @typescript-eslint/no-explicit-any export type Parser = (transformer: Transformer, block: T) => T; @@ -40,11 +40,12 @@ export const createItemsParser = (fields: string[]) => (transformer: Transformer export function yfmTransformer( lang: Lang, content: string, - additionalPlugins: MarkdownItPluginCb[] = [], + options: {plugins?: MarkdownItPluginCb[]} = {}, ) { + const {plugins = []} = options; const {html} = fullTransform(content, { lang, - plugins: [...defaultPlugins, ...additionalPlugins], + plugins: [...defaultPlugins, ...plugins], }); return html; diff --git a/src/text-transform/transformers.ts b/src/text-transform/transformers.ts index a30c57060..e9b8f5b42 100644 --- a/src/text-transform/transformers.ts +++ b/src/text-transform/transformers.ts @@ -19,7 +19,7 @@ export type ContentTransformerProps = { lang: Lang; customConfig?: {}; vars?: ContentVariables; - additionalPlugins?: MarkdownItPluginCb[]; + plugins?: MarkdownItPluginCb[]; }; }; @@ -27,20 +27,21 @@ function transformBlocks( blocks: ConstructorBlock[], lang: Lang, customConfig = {}, - additionalPlugins: MarkdownItPluginCb[] = [], + options: {plugins?: MarkdownItPluginCb[]} = {}, ) { const fullConfig = {...config, ...customConfig}; + const {plugins = []} = options; const clonedBlocks = _.cloneDeep(blocks); - return clonedBlocks.map((block) => transformBlock(lang, fullConfig, block, additionalPlugins)); + return clonedBlocks.map((block) => transformBlock(lang, fullConfig, block, plugins)); } function transformBlock( lang: Lang, blocksConfig: BlocksConfig, block: ConstructorBlock, - additionalPlugins: MarkdownItPluginCb[], + plugins: MarkdownItPluginCb[], ) { const blockConfig = blocksConfig[block.type]; @@ -57,7 +58,7 @@ function transformBlock( const {fields, transformer: transformerRaw, parser} = transformConfig; const transformer: Transformer = (content) => // eslint-disable-next-line no-useless-call - transformerRaw.call(null, lang, content, additionalPlugins); + transformerRaw.call(null, lang, content, {plugins}); if (fields) { (fields as (keyof typeof block)[]).forEach((field) => { @@ -83,12 +84,14 @@ function transformBlock( } export const contentTransformer = ({content, options}: ContentTransformerProps) => { - const {lang, customConfig = {}, vars, additionalPlugins = []} = options; + const {lang, customConfig = {}, vars, plugins = []} = options; const {blocks = []} = ( vars ? filterContent(content as FilterableContent, vars) : content ) as PageContent; - const transformedBlocks = transformBlocks(blocks, lang, customConfig, additionalPlugins); + const transformedBlocks = transformBlocks(blocks, lang, customConfig, { + plugins, + }); return { blocks: transformedBlocks,