diff --git a/src/transform/index.ts b/src/transform/index.ts index c88954f1..08f01c53 100644 --- a/src/transform/index.ts +++ b/src/transform/index.ts @@ -30,7 +30,7 @@ function emitResult(html: string, env: EnvType): OutputType { } // eslint-disable-next-line consistent-return -function transform(originInput: string, options: OptionsType = {}) { +export function transform(originInput: string, options: OptionsType = {}) { const input = applyLiquid(originInput, options); const {parse, compile, env} = initMarkdownit(options); @@ -41,6 +41,10 @@ function transform(originInput: string, options: OptionsType = {}) { } } +export function transformInline(originInput: string, options: OptionsType = {}) { + return transform(originInput, {...options, renderInline: true}); +} + export = transform; // eslint-disable-next-line @typescript-eslint/no-namespace, no-redeclare -- backward compatibility diff --git a/src/transform/md.ts b/src/transform/md.ts index fd8fced1..d788b8fb 100644 --- a/src/transform/md.ts +++ b/src/transform/md.ts @@ -118,10 +118,12 @@ function initParser(md: MarkdownIt, options: OptionsType, env: EnvType) { } function initCompiler(md: MarkdownIt, options: OptionsType, env: EnvType) { - const {needToSanitizeHtml = true, sanitizeOptions} = options; + const {needToSanitizeHtml = true, renderInline = false, sanitizeOptions} = options; return (tokens: Token[]) => { - const html = md.renderer.render(tokens, md.options, env); + const html = renderInline + ? md.renderer.renderInline(tokens, md.options, env) + : md.renderer.render(tokens, md.options, env); return needToSanitizeHtml ? sanitizeHtml(html, sanitizeOptions) : html; }; diff --git a/src/transform/typings.ts b/src/transform/typings.ts index c8ff9e55..79ac76db 100644 --- a/src/transform/typings.ts +++ b/src/transform/typings.ts @@ -48,6 +48,7 @@ export interface OptionsType { rootPublicPath?: string; transformLink?: (href: string) => string; getPublicPath?: (options: OptionsType, href?: string) => string; + renderInline?: boolean; [x: string]: unknown; }