MCPcopy Index your code
hub / github.com/simstudioai/sim / extractTextFromDocsBody

Function extractTextFromDocsBody

apps/sim/connectors/google-docs/google-docs.ts:81–108  ·  view source on GitHub ↗

* Extracts plain text from a Google Docs API structured document response. * Headings are prefixed with Markdown-style `#` markers.

(doc: DocsDocument)

Source from the content-addressed store, hash-verified

79 * Headings are prefixed with Markdown-style `#` markers.
80 */
81function extractTextFromDocsBody(doc: DocsDocument): string {
82 const elements = doc.body?.content
83 if (!elements) return ''
84
85 const parts: string[] = []
86
87 for (const element of elements) {
88 const paragraph = element.paragraph
89 if (!paragraph?.elements) continue
90
91 const prefix = headingPrefix(paragraph.paragraphStyle?.namedStyleType)
92 /**
93 * Each paragraph's final `textRun.content` already ends with `\n`. Strip
94 * it before joining with `\n` so a heading followed by a body paragraph
95 * is separated by a single newline, not two.
96 */
97 const text = paragraph.elements
98 .map((el) => el.textRun?.content ?? '')
99 .join('')
100 .replace(/\n+$/, '')
101
102 if (text.trim()) {
103 parts.push(`${prefix}${text}`)
104 }
105 }
106
107 return parts.join('\n').trim()
108}
109
110/**
111 * Fetches the structured content of a Google Doc via the Docs API and

Callers 1

fetchDocContentFunction · 0.85

Calls 4

headingPrefixFunction · 0.85
joinMethod · 0.80
replaceMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected