Pure readers over a document from get-document: tabs, plain text,
paragraphs, headings, tables and the body's end index. Each reader
takes a whole document, in which case it covers every tab when the
document was fetched with includeTabsContent.
Functions
all-tabs
fn (doc: Map): Vec
Every tab of a document fetched with includeTabsContent, parents
before their children, in tab order. Empty for a document fetched
without it.
Example
doc {tabs: [{
tabProperties: {tabId: "t.0", title: "Notes"},
childTabs: [{tabProperties: {tabId: "t.1", title: "Draft"}}]
}]}
map(::google::docs::content/all-tabs(doc), %.tabProperties.title) // ["Notes", "Draft"]
bodies
fn (doc: Map): Vec
Every Body in a document: one per tab when it was fetched with
includeTabsContent, otherwise its single body. Pass each to
body-text, body-paragraphs or body-tables.
Example
::google::docs::content/bodies({body: {content: []}}) // [{content: []}]
body-paragraphs
fn (body: Map): Vec
A Body's top-level paragraphs, in the shape paragraphs returns. Use
it to read one tab; paragraphs covers the whole document.
Example
body {content: [{startIndex: 1, endIndex: 4, paragraph: {elements: [{textRun: {content: "Hi\n"}}]}}]}
first(::google::docs::content/body-paragraphs(body)).text // "Hi"
body-tables
fn (body: Map): Vec
A Body's top-level tables, in the shape tables returns. Use it to
read one tab; tables covers the whole document.
Example
body {content: [{startIndex: 2, endIndex: 5, table: {tableRows: []}}]}
::google::docs::content/body-tables(body) // [{start: 2, end: 5, rows: []}]
body-text
fn (body: Map): Str
A Body's text.
Example
body {content: [
{paragraph: {elements: [{textRun: {content: "Hello\n"}}]}},
{paragraph: {elements: [{textRun: {content: "World\n"}}]}}
]}
::google::docs::content/body-text(body) // "Hello\nWorld\n"
content-text
fn (content: Any): Str
The text of a Vec of StructuralElements, descending into tables and tables of contents.
Example
::google::docs::content/content-text([
{paragraph: {elements: [{textRun: {content: "One\n"}}]}},
{paragraph: {elements: [{textRun: {content: "Two\n"}}]}}
]) // "One\nTwo\n"
document-text
fn (doc: Map): Str
The whole document's body text, tab after tab.
Example
doc {tabs: [{tabProperties: {tabId: "t.0", title: "Notes"}, documentTab: {body: {content: [
{paragraph: {elements: [{textRun: {content: "Hello\n"}}]}}
]}}}]}
::google::docs::content/document-text(doc) // "Hello\n"
element-text
fn (element: Map): Str
A StructuralElement's text. Table cells end with the newline of their last paragraph, so cells read one per line.
Example
::google::docs::content/element-text({paragraph: {elements: [{textRun: {content: "Hi\n"}}]}}) // "Hi\n"
::google::docs::content/element-text({sectionBreak: {}}) // ""
end-index
fn (body: Map): Int
The index just past a Body's last element. A body always ends with
a newline that cannot be deleted, so the last insertable index is
sub(end-index(body), 1).
Example
::google::docs::content/end-index({content: [{startIndex: 1, endIndex: 12}]}) // 12
::google::docs::content/end-index({content: []}) // 1
find-tab
fn (doc: Map, id-or-title: Str): Map?
The tab with this id, or else this title, or null.
Example
doc {tabs: [{
tabProperties: {tabId: "t.0", title: "Notes"},
childTabs: [{tabProperties: {tabId: "t.1", title: "Draft"}}]
}]}
::google::docs::content/tab-id(::google::docs::content/find-tab(doc, "Draft")) // "t.1"
::google::docs::content/find-tab(doc, "Missing") // null
headings
fn (doc: Map): Vec
The paragraphs styled as TITLE, SUBTITLE or HEADING_1 to
HEADING_6, in the shape of paragraphs.
Example
doc {body: {content: [
{startIndex: 1, endIndex: 7, paragraph: {
elements: [{textRun: {content: "Title\n"}}],
paragraphStyle: {namedStyleType: "HEADING_1"}
}}
]}}
map(::google::docs::content/headings(doc), %.text) // ["Title"]
paragraph-text
fn (paragraph: Map): Str
A Paragraph's text: its text runs and auto text joined, with the trailing newline Docs stores.
Example
::google::docs::content/paragraph-text({elements: [
{textRun: {content: "Hello "}},
{textRun: {content: "world\n"}}
]}) // "Hello world\n"
paragraphs
fn (doc: Map): Vec
Top-level paragraphs as {text, style, start, end, bullet}: text has
no trailing newline, style is the namedStyleType (e.g.
"HEADING_1"), and start and end are the indexes to pass to
::google::docs::requests. Paragraphs inside tables are not included.
Example
doc {body: {content: [
{startIndex: 1, endIndex: 7, paragraph: {
elements: [{textRun: {content: "Title\n"}}],
paragraphStyle: {namedStyleType: "HEADING_1"}
}}
]}}
::google::docs::content/paragraphs(doc) // [{text: "Title", style: "HEADING_1", start: 1, end: 7, bullet: false}]
tab-body
fn (tab: Map): Map?
A tab's Body, or null.
Example
::google::docs::content/tab-body({documentTab: {body: {content: []}}}) // {content: []}
tab-id
fn (tab: Map): Str?
A tab's id, or null. Pass it as tabId in the options of read-text
and the ::google::docs::requests builders.
Example
::google::docs::content/tab-id({tabProperties: {tabId: "t.0", title: "Notes"}}) // "t.0"
tab-text
fn (tab: Map): Str
A tab's body text, empty when the tab has no body.
Example
::google::docs::content/tab-text({documentTab: {body: {content: [
{paragraph: {elements: [{textRun: {content: "Hi\n"}}]}}
]}}}) // "Hi\n"
::google::docs::content/tab-text({}) // ""
tab-title
fn (tab: Map): Str?
A tab's title, or null.
Example
::google::docs::content/tab-title({tabProperties: {tabId: "t.0", title: "Notes"}}) // "Notes"
tables
fn (doc: Map): Vec
Top-level tables as {start, end, rows}, with rows a Vec of rows of
cell text. start is the table start index that
::google::docs::requests table builders take.
Example
doc {body: {content: [{startIndex: 2, endIndex: 12, table: {tableRows: [{tableCells: [
{content: [{paragraph: {elements: [{textRun: {content: "a\n"}}]}}]},
{content: [{paragraph: {elements: [{textRun: {content: "b\n"}}]}}]}
]}]}}]}}
::google::docs::content/tables(doc) // [{start: 2, end: 12, rows: [["a", "b"]]}]