Skip to content

Commit

Permalink
feat: Add transformInline method
Browse files Browse the repository at this point in the history
Fixes #393
  • Loading branch information
3y3 committed Aug 2, 2024
1 parent ac1175c commit b18929d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/transform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/transform/md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions src/transform/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface OptionsType {
rootPublicPath?: string;
transformLink?: (href: string) => string;
getPublicPath?: (options: OptionsType, href?: string) => string;
renderInline?: boolean;
[x: string]: unknown;
}

Expand Down

0 comments on commit b18929d

Please sign in to comment.