{"record":{"id":"e19040f52eed6caa","repo":"siyuan-note/siyuan","slug":"pandoc-output-is-too-large","errorCode":null,"errorMessage":"pandoc output is too large","messagePattern":"pandoc output is too large","errorType":"validation","errorClass":null,"httpStatus":200,"severity":"error","filePath":"kernel/api/lute_clipboard_math.go","lineNumber":107,"sourceCode":"\t}\n\tmarkdown, converted, err := convertClipboardMathWithRunner(\"\", \"\", base64.StdEncoding.EncodeToString(input), runClipboardMathPandoc)\n\tif err != nil {\n\t\tlogging.LogWarnf(\"convert Office HTML clipboard math with pandoc failed: %s\", err)\n\t}\n\treturn markdown, converted\n}\n\nfunc convertClipboardMathWithRunner(mathML, office, wps string, runner clipboardMathPandocRunner) (markdown string, converted bool, err error) {\n\tfrom, input, ok := clipboardMathPandocInput(mathML, office, wps)\n\tif !ok {\n\t\treturn\n\t}\n\toutput, err := runner(from, \"json\", input)\n\tif err != nil {\n\t\treturn \"\", false, err\n\t}\n\tif len(output) > maxClipboardMathPandocOutput {\n\t\treturn \"\", false, fmt.Errorf(\"pandoc output is too large\")\n\t}\n\tmath, ok := parsePandocSingleMath(output)\n\tif !ok {\n\t\tif from != \"docx\" || !isSimplePandocMathDocument(output) {\n\t\t\treturn \"\", false, nil\n\t\t}\n\t\tmarkdownOutput, writeErr := runner(\"json\", \"markdown-raw_attribute\", output)\n\t\tif writeErr != nil {\n\t\t\treturn \"\", false, writeErr\n\t\t}\n\t\tif len(markdownOutput) > maxClipboardMathPandocOutput {\n\t\t\treturn \"\", false, fmt.Errorf(\"pandoc output is too large\")\n\t\t}\n\t\tmarkdown = strings.TrimSpace(strings.ReplaceAll(string(markdownOutput), \"<!-- -->\", \"\"))\n\t\treturn markdown, markdown != \"\", nil\n\t}\n\tif math.display {\n\t\treturn \"$$\\n\" + math.tex + \"\\n$$\", true, nil","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/api/lute_clipboard_math.go#L89-L125","documentation":"convertClipboardMathWithRunner converts clipboard math (e.g. Word/WPS OMML) to Markdown via a pandoc runner. To avoid pathological memory/CPU blowups from oversized pandoc output, any JSON conversion output exceeding maxClipboardMathPandocOutput is rejected with this error instead of being parsed. It is a deliberate safety guard, not a pandoc failure.","triggerScenarios":"Calling convertClipboardMath or convertOfficeHTMLClipboardMath with clipboard content whose pandoc JSON conversion output exceeds maxClipboardMathPandocOutput bytes; the runner itself succeeds but the size check at lute_clipboard_math.go:107 fails.","commonSituations":"Pasting very large Word/WPS documents full of equations into the editor; a clipboard event carrying an entire document rather than a single formula; pathological content that makes pandoc's JSON AST representation balloon well beyond the original text size.","solutions":["Reduce the amount of clipboard content converted at once - convert a single formula or equation region, not the whole document.","Strip non-math content from the HTML/clipboard payload before calling the conversion.","Raise maxClipboardMathPandocOutput if legitimate large conversions must be supported, accepting the memory trade-off.","Treat the error as 'skip math conversion' and fall back to plain paste handling."],"exampleFix":"// before: converting the whole clipboard HTML\nmath, ok, err := convertClipboardMath(clipboardHTML)\n// after: cap input size before conversion\nif len(clipboardHTML) > maxClipboardMathInputSize {\n    clipboardHTML = truncateToMathRegion(clipboardHTML)\n}\nmath, ok, err := convertClipboardMath(clipboardHTML)","handlingStrategy":"try-catch","validationCode":"if (new Blob([clipboardHTML]).size > MAX_INPUT_BYTES) {\n  // trim to math region or warn user before converting\n}","typeGuard":"function isReasonablePandocOutput(out: Uint8Array, limit: number): boolean {\n  return out.byteLength > 0 && out.byteLength <= limit;\n}","tryCatchPattern":"try {\n  const md = await convertClipboardMath(html);\n} catch (e) {\n  if (String(e.message).includes(\"too large\")) {\n    pasteRaw(html); // graceful fallback\n  } else { throw e; }\n}","preventionTips":["Convert only the selected formula, not entire documents.","Pre-trim clipboard HTML to the math region before calling the API.","Log output sizes in dev to calibrate your expectations of the limit.","Always code a raw-paste fallback path for conversion errors."],"tags":["pandoc","clipboard","size-limit","math-conversion"],"backgroundTag":"payload-too-large","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}