MCPcopy Create free account
hub / github.com/openclaw/gogcli / runMarkdown

Method runMarkdown

internal/cmd/docs_edit.go:1057–1124  ·  view source on GitHub ↗

runMarkdown converts the supplied content from markdown to Google Docs formatting and inserts it at insertIndex. It reuses the same converter + insertion helper that backs `docs write --markdown` and the non-replacing branch of `docs update --markdown`, so headings, fenced code blocks, lists, tables

(
	ctx context.Context,
	svc *docs.Service,
	docID string,
	insertIndex int64,
	requiredRevisionID string,
	content string,
)

Source from the content-addressed store, hash-verified

1055// branch of `docs update --markdown`, so headings, fenced code blocks, lists,
1056// tables and images render identically regardless of which command placed them.
1057func (c *DocsInsertCmd) runMarkdown(
1058 ctx context.Context,
1059 svc *docs.Service,
1060 docID string,
1061 insertIndex int64,
1062 requiredRevisionID string,
1063 content string,
1064) error {
1065 markdown := prepareMarkdown(content)
1066 insertResult, err := insertPreparedDocsMarkdownAtWithWriteControl(
1067 ctx,
1068 svc,
1069 docID,
1070 insertIndex,
1071 markdown,
1072 c.Tab,
1073 true,
1074 docsRequiredRevisionWriteControl(requiredRevisionID),
1075 )
1076 if err != nil {
1077 if isDocsNotFound(err) {
1078 return fmt.Errorf("doc not found or not a Google Doc (id=%s)", docID)
1079 }
1080 return err
1081 }
1082 requestCount := insertResult.RequestCount
1083 if markdownMayContainHeadingLinks(markdown.cleaned) {
1084 explicitHeadingAnchors := docsmarkdown.ExplicitHeadingAnchors(markdown.cleaned)
1085 rewritten, rewriteErr := rewriteMarkdownHeadingLinksInRange(
1086 ctx,
1087 svc,
1088 docID,
1089 c.Tab,
1090 explicitHeadingAnchors,
1091 insertResult.ContentStart,
1092 insertResult.ContentEnd,
1093 )
1094 if rewriteErr != nil {
1095 return fmt.Errorf("rewrite heading links: %w", rewriteErr)
1096 }
1097 requestCount += rewritten
1098 }
1099
1100 if outfmt.IsJSON(ctx) {
1101 payload := map[string]any{
1102 "documentId": docID,
1103 "inserted": insertResult.Inserted,
1104 "requests": requestCount,
1105 "atIndex": insertIndex,
1106 "markdown": true,
1107 }
1108 if c.Tab != "" {
1109 payload["tabId"] = c.Tab
1110 }
1111 return outfmt.WriteJSON(ctx, stdoutWriter(ctx), payload)
1112 }
1113
1114 u := ui.FromContext(ctx)

Callers 1

RunMethod · 0.95

Calls 14

ExplicitHeadingAnchorsFunction · 0.92
IsJSONFunction · 0.92
WriteJSONFunction · 0.92
FromContextFunction · 0.92
prepareMarkdownFunction · 0.85
isDocsNotFoundFunction · 0.85
stdoutWriterFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected