siyuan-note/siyuan · error

pandoc output is too large

Error message

pandoc output is too large

What it means

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.

Source

Thrown at kernel/api/lute_clipboard_math.go:107

	}
	markdown, converted, err := convertClipboardMathWithRunner("", "", base64.StdEncoding.EncodeToString(input), runClipboardMathPandoc)
	if err != nil {
		logging.LogWarnf("convert Office HTML clipboard math with pandoc failed: %s", err)
	}
	return markdown, converted
}

func convertClipboardMathWithRunner(mathML, office, wps string, runner clipboardMathPandocRunner) (markdown string, converted bool, err error) {
	from, input, ok := clipboardMathPandocInput(mathML, office, wps)
	if !ok {
		return
	}
	output, err := runner(from, "json", input)
	if err != nil {
		return "", false, err
	}
	if len(output) > maxClipboardMathPandocOutput {
		return "", false, fmt.Errorf("pandoc output is too large")
	}
	math, ok := parsePandocSingleMath(output)
	if !ok {
		if from != "docx" || !isSimplePandocMathDocument(output) {
			return "", false, nil
		}
		markdownOutput, writeErr := runner("json", "markdown-raw_attribute", output)
		if writeErr != nil {
			return "", false, writeErr
		}
		if len(markdownOutput) > maxClipboardMathPandocOutput {
			return "", false, fmt.Errorf("pandoc output is too large")
		}
		markdown = strings.TrimSpace(strings.ReplaceAll(string(markdownOutput), "<!-- -->", ""))
		return markdown, markdown != "", nil
	}
	if math.display {
		return "$$\n" + math.tex + "\n$$", true, nil

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Reduce the amount of clipboard content converted at once - convert a single formula or equation region, not the whole document.
  2. Strip non-math content from the HTML/clipboard payload before calling the conversion.
  3. Raise maxClipboardMathPandocOutput if legitimate large conversions must be supported, accepting the memory trade-off.
  4. Treat the error as 'skip math conversion' and fall back to plain paste handling.

Example fix

// before: converting the whole clipboard HTML
math, ok, err := convertClipboardMath(clipboardHTML)
// after: cap input size before conversion
if len(clipboardHTML) > maxClipboardMathInputSize {
    clipboardHTML = truncateToMathRegion(clipboardHTML)
}
math, ok, err := convertClipboardMath(clipboardHTML)
Defensive patterns

Strategy: try-catch

Validate before calling

if (new Blob([clipboardHTML]).size > MAX_INPUT_BYTES) {
  // trim to math region or warn user before converting
}

Type guard

function isReasonablePandocOutput(out: Uint8Array, limit: number): boolean {
  return out.byteLength > 0 && out.byteLength <= limit;
}

Try / catch

try {
  const md = await convertClipboardMath(html);
} catch (e) {
  if (String(e.message).includes("too large")) {
    pasteRaw(html); // graceful fallback
  } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/e19040f52eed6caa. Report an issue: GitHub.