Skip to content

Commit 8da40b0

Browse files
committed
docs(sdk): context-driven formatting guidance for markdown inserts
1 parent 16d6a52 commit 8da40b0

2 files changed

Lines changed: 18 additions & 19 deletions

File tree

packages/document-api/src/contract/operation-definitions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ export const INTENT_GROUP_META: Record<string, IntentGroupMeta> = {
148148
'ALWAYS use action "insert" with type "markdown" to create headings, paragraphs, or any block content — this is faster and creates proper document structure in one call. Do NOT use superdoc_create for headings or paragraphs. ' +
149149
'The markdown parser creates headings from # markers (# = Heading1, ## = Heading2), bold from **text**, italic from *text*, and numbered/bullet lists. ' +
150150
'Position markdown inserts with "target" (a BlockNodeAddress like {kind:"block", nodeType, nodeId}) and "placement" (before, after, insideStart, insideEnd). Without a target, content appends at the end of the document. ' +
151-
'IMPORTANT: After a markdown insert, follow up with ONE superdoc_mutations call using format.apply steps to match the document style. ' +
152-
'Each format.apply step accepts "inline" (fontFamily, fontSize, bold, underline, color) AND "alignment" ("left","center","right","justify") in the same step — combine both in one step per block. ' +
153-
'Look at nearby headings and paragraphs in the get_content response and copy their exact formatting. Do NOT invent values — match what is already in the document. ' +
154-
'ALWAYS include fontSize on headings — markdown headings inherit a large default size that must be overridden to match the document. Use scope: "block" so formatting covers the entire paragraph. ' +
151+
'IMPORTANT: After a markdown insert, analyze the document context (what kind of document, how titles and body text are styled) and follow up with ONE superdoc_mutations call to format inserted blocks so they look like they belong. ' +
152+
'Each format.apply step accepts "inline" (fontFamily, fontSize, bold, underline, color), "alignment", and "scope" in the same step. ' +
153+
'Use scope: "block" so formatting covers the entire paragraph. ALWAYS include fontSize — especially on headings, which inherit a large default size that must be overridden. ' +
154+
'Copy exact formatting from nearby blocks in the get_content response. Do NOT invent values. Your inserted content must be visually indistinguishable from the rest of the document. ' +
155155
'Also supports replace, delete, and undo/redo. For replace and delete, pass a "ref" from superdoc_search or superdoc_get_content blocks. ' +
156156
'A search ref covers only the matched substring; a block ref covers the entire block text, so use block refs when rewriting or shortening whole paragraphs. ' +
157157
'Refs expire after any mutation; always re-search before the next edit. ' +

packages/sdk/tools/prompt-templates/system-prompt-core.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,15 @@ Use preset "disc" for bullets, "decimal" for numbered. WARNING: the range conver
130130

131131
### Insert content into a document (new or existing)
132132

133-
Markdown insert creates block structure but uses default formatting. You MUST follow up with formatting to match the document's existing style.
133+
Markdown insert creates block structure but uses default formatting. You MUST follow up with formatting so inserted content looks like it belongs in the document.
134134

135-
**Step 1: Read existing formatting** from the initial get_content blocks response. Pay special attention to:
136-
- **Nearby headings/titles**: look at their fontFamily, fontSize, bold, underline, alignment (especially center vs justify vs left). Your new headings must match these exactly.
137-
- **Body paragraphs**: note fontFamily, fontSize, color, alignment. Your new paragraphs must match.
138-
- Match the style of the nearest similar element, not arbitrary values.
135+
**Step 1: Understand the document context** from the get_content blocks response. Before inserting anything, analyze:
136+
- What kind of document is this? (contract, letter, certificate, report, etc.)
137+
- How are titles/headings styled? (centered? left? bold? underlined? what fontSize?)
138+
- How is body text styled? (fontFamily, fontSize, alignment, color)
139+
- What formatting conventions does the document follow?
140+
141+
Your inserted content must be indistinguishable from the existing content. If titles are centered 10pt Times New Roman with no bold, your heading must be centered 10pt Times New Roman with no bold. If body text is justified 12pt with underline, your paragraphs must be justified 12pt with underline.
139142

140143
**Step 2: Insert content with markdown:**
141144

@@ -146,24 +149,20 @@ superdoc_edit({action: "insert", type: "markdown",
146149
value: "# Executive Summary\n\nThis agreement sets forth the principal terms..."})
147150
```
148151

149-
**Step 3: Apply ALL formatting in a SINGLE superdoc_mutations call.** Each format.apply step accepts `inline` (text styles), `alignment` (paragraph alignment), and `scope` — combine them all in one step per block.
152+
**Step 3: Format ALL inserted blocks in ONE superdoc_mutations call.** Each format.apply step accepts `inline`, `alignment`, and `scope: "block"`.
153+
154+
Use `scope: "block"` so the formatting covers the entire paragraph (not just the matched text). The text pattern only needs to identify which block.
150155

151-
ALWAYS use `scope: "block"` after markdown inserts. This makes the formatting cover the entire paragraph, not just the matched text pattern. The pattern only needs to uniquely identify which paragraph — a short prefix is enough.
156+
ALWAYS include `fontSize` on every block, especially headings. Markdown headings inherit a large default font size that must be overridden. If a block in get_content doesn't show fontSize, use the fontSize from the nearest block that does.
152157

153-
Example: if the document has centered, underlined, 12pt headings and justified 12pt body text:
158+
Example: document has centered, non-bold, 12pt titles and justified 12pt body text:
154159
```
155160
superdoc_mutations({action: "apply", atomic: true, steps: [
156-
{id: "f1", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "Executive Summary"}, require: "first"}, args: {inline: {fontFamily: "Times New Roman, serif", fontSize: 12, underline: true}, alignment: "center", scope: "block"}},
161+
{id: "f1", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "Executive Summary"}, require: "first"}, args: {inline: {fontFamily: "Times New Roman, serif", fontSize: 12}, alignment: "center", scope: "block"}},
157162
{id: "f2", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "This agreement sets forth"}, require: "first"}, args: {inline: {fontFamily: "Times New Roman, serif", fontSize: 12, color: "#000000"}, alignment: "justify", scope: "block"}}
158163
]})
159164
```
160165

161-
CRITICAL rules for formatting after insert:
162-
- Do NOT guess formatting values. Copy them from the existing document blocks you read in step 1.
163-
- Use `scope: "block"` so the formatting covers the ENTIRE paragraph, not just the matched text.
164-
- ALWAYS include `fontSize` on headings. Markdown headings inherit a large default font size from the Heading1 style. You MUST override it with the fontSize used by existing titles/headings in the document (typically the same as body text, e.g., 10pt or 12pt).
165-
- If the document blocks don't show a fontSize, use the fontSize from the nearest block that does have one.
166-
167166
Total: 3 calls (read + insert + format-all-in-one-batch). Never more.
168167

169168
### Batch multiple text edits atomically

0 commit comments

Comments
 (0)