replaceMarkdownLocally renders Markdown through Docs batchUpdate after clearing the selected body. This preserves tab targeting and table-cell line breaks that Drive's whole-document converter cannot represent.
( ctx context.Context, flags *RootFlags, docID string, markdown preparedMarkdown, plan docsedit.MarkdownWritePlan, )
| 512 | // clearing the selected body. This preserves tab targeting and table-cell |
| 513 | // line breaks that Drive's whole-document converter cannot represent. |
| 514 | func (c *DocsWriteCmd) replaceMarkdownLocally( |
| 515 | ctx context.Context, |
| 516 | flags *RootFlags, |
| 517 | docID string, |
| 518 | markdown preparedMarkdown, |
| 519 | plan docsedit.MarkdownWritePlan, |
| 520 | ) error { |
| 521 | dryRunPayload := map[string]any{ |
| 522 | "document_id": docID, |
| 523 | "written": len(plan.Markdown), |
| 524 | "append": false, |
| 525 | "replace": true, |
| 526 | "markdown": true, |
| 527 | "pageless": c.Pageless, |
| 528 | "tab": plan.Tab, |
| 529 | "images": plan.ImageCount, |
| 530 | "check_orphans": plan.CheckOrphans, |
| 531 | } |
| 532 | for k, v := range c.Layout.dryRunPayload() { |
| 533 | dryRunPayload[k] = v |
| 534 | } |
| 535 | if err := dryRunExit(ctx, flags, "docs.write", dryRunPayload); err != nil { |
| 536 | return err |
| 537 | } |
| 538 | |
| 539 | var svc *docs.Service |
| 540 | var err error |
| 541 | if plan.CheckOrphans { |
| 542 | account, driveSvc, driveErr := requireDriveService(ctx, flags) |
| 543 | if driveErr != nil { |
| 544 | return driveErr |
| 545 | } |
| 546 | svc, err = docsService(ctx, account) |
| 547 | if err != nil { |
| 548 | return err |
| 549 | } |
| 550 | orphans, resolvedTabID, orphanErr := findDocsWriteMarkdownOrphans( |
| 551 | ctx, |
| 552 | driveSvc, |
| 553 | svc, |
| 554 | docID, |
| 555 | markdown, |
| 556 | plan.Tab, |
| 557 | plan.OrphanScopeWholeDocument, |
| 558 | ) |
| 559 | if orphanErr != nil { |
| 560 | return orphanErr |
| 561 | } |
| 562 | if resultErr := writeDocsWriteOrphanResult(ctx, docID, resolvedTabID, orphans); resultErr != nil { |
| 563 | return resultErr |
| 564 | } |
| 565 | c.Tab = resolvedTabID |
| 566 | } else { |
| 567 | svc, err = requireDocsService(ctx, flags) |
| 568 | } |
| 569 | if err != nil { |
| 570 | return err |
| 571 | } |
no test coverage detected