Skip to content

Commit 4aecff1

Browse files
fix(docs-sync): harden pandoc rendering
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <[email protected]>
1 parent 49c568e commit 4aecff1

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

packages/yapi-mcp/src/docs/markdown.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,18 @@ export function preprocessMarkdown(markdown: string, options: MarkdownRenderOpti
439439

440440
export function markdownToHtml(markdown: string): string {
441441
if (isPandocAvailable()) {
442-
return execFileSync("pandoc", ["-f", "gfm+hard_line_breaks", "-t", "html"], {
443-
input: markdown,
444-
encoding: "utf8",
445-
});
442+
const maxBufferEnv = Number(process.env.YAPI_PANDOC_MAX_BUFFER ?? NaN);
443+
const maxBuffer = Number.isFinite(maxBufferEnv) ? maxBufferEnv : 64 * 1024 * 1024;
444+
try {
445+
return execFileSync("pandoc", ["-f", "gfm+hard_line_breaks", "-t", "html"], {
446+
input: markdown,
447+
encoding: "utf8",
448+
maxBuffer,
449+
});
450+
} catch (error) {
451+
const message = formatRenderError(error);
452+
console.warn(`pandoc failed, fallback to markdown-it. reason: ${message}`);
453+
}
446454
}
447455
if (!cachedMarkdownIt) {
448456
cachedMarkdownIt = new MarkdownIt({ html: true, linkify: true, breaks: true });

packages/yapi-mcp/src/yapi-cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,8 @@ async function runDocsSync(rawArgs: string[]): Promise<number> {
19001900
try {
19011901
if (!isPandocAvailable()) {
19021902
console.warn("pandoc not found, fallback to markdown-it renderer.");
1903-
console.warn("Install pandoc: https://pandoc.org/installing.html");
1903+
console.warn("Install pandoc (macOS): brew install pandoc");
1904+
console.warn("More info: https://pandoc.org/installing.html");
19041905
}
19051906
if (!options.noMermaid && !isMmdcAvailable()) {
19061907
console.warn("mmdc not found, Mermaid blocks will stay as code.");

0 commit comments

Comments
 (0)