Skip to content
Open
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: 4 additions & 5 deletions src/inline-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,11 @@ function renderInline(
}
// Render footnote content inline
try {
if (!context.renderBlock) {
throw new Error('renderBlock not available in context');
}
const content = def.children
.map((child) => {
// Import renderBlock only when needed to avoid circular dependencies
const { renderBlock } = require('./block-renderer.js');
return renderBlock(child, 0, context);
})
.map((child) => context.renderBlock!(child, 0, context))
.filter(isNonEmpty)
.join(' '); // Join blocks with space for inline footnote
return `#footnote[${content.trim()}]`;
Expand Down
4 changes: 3 additions & 1 deletion src/markdown2typst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { parseMarkdown } from './parser.js';
import { collectDefinitions, collectFootnotes, findLeadingH1 } from './collectors.js';
import { parseFrontmatter, mergeMetadata } from './frontmatter.js';
import { buildOutput } from './output-builder.js';
import { renderBlock } from './block-renderer.js';

// Re-export types for public API
export type { Markdown2TypstOptions, ConversionError, ErrorCallback } from './types.js';
Expand Down Expand Up @@ -76,7 +77,8 @@ export function markdown2typst(markdown: string, options: Markdown2TypstOptions
definitions,
footnoteDefinitions,
onError: options.onError,
warnings: { externalImages: false }
warnings: { externalImages: false },
renderBlock
};
return buildOutput(tree, metadata, leadingH1?.index ?? null, context);
} catch (error) {
Expand Down
11 changes: 11 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ export type ConversionWarnings = {
externalImages: boolean;
};

/**
* Block renderer function type for dependency injection
*/
export type BlockRenderer = (
node: import('mdast').Content,
indentLevel: number,
context: RenderContext
) => string | null;

/**
* Context for rendering nodes
*/
Expand All @@ -153,4 +162,6 @@ export type RenderContext = {
onError?: ErrorCallback;
/** Track conversion warnings for generating helper functions */
warnings: ConversionWarnings;
/** Block renderer function (injected to avoid circular imports) */
renderBlock?: BlockRenderer;
};