How do I get a Google Apps Script Document Outline from the API?











up vote
0
down vote

favorite












I am able to get the contents of a documents outline by searching all the paragraphs and seeing the heading each paragraph is using. This works but isn't ideal. If I manually remove an item from the outline, it doesn't change the heading of that item to normal. Therefore when I run my code again it'll detect the removed item as still being part of the outline since it's heading matches one used for the outline.



var searchHeading = DocumentApp.ParagraphHeading.HEADING4;
var paragraphs = getParagraphs();
return paragraphs.filter(function(paragraph) {
return (paragraph.header == searchHeading);
});

function getParagraphs() {
var paragraphs = DocumentApp.getActiveDocument().getBody().getParagraphs();
return paragraphs.map(function(p, index) {
return {
paragraph: p.getText(),
header: p.getHeading(),
id: index
};
});
}


Is there anyway to get the contents of the outline without parsing each paragraph and filtering those whose header matches a specific heading, ideally from an API call?



EDIT: Added getParagraphs()










share|improve this question
























  • I'm sorry for my poor English skill. In order to understand correctly the result you want and the current result, can I ask you about your question? Can you provide about the detail of getParagraphs() and the current result? From your current result, can you also provide the result you want?
    – Tanaike
    Nov 9 at 0:20










  • No problem, I updated the question with the implementation for getParagraphs(). It returns a list of custom paragraph objects. There are the same as google paragrahps but also have an id for their order. This function works fine, but ultimately what I want is an API call to get the contents of a documents outline.
    – Alexsh
    Nov 12 at 16:38










  • Thank you for replying it.
    – Tanaike
    Nov 12 at 23:15















up vote
0
down vote

favorite












I am able to get the contents of a documents outline by searching all the paragraphs and seeing the heading each paragraph is using. This works but isn't ideal. If I manually remove an item from the outline, it doesn't change the heading of that item to normal. Therefore when I run my code again it'll detect the removed item as still being part of the outline since it's heading matches one used for the outline.



var searchHeading = DocumentApp.ParagraphHeading.HEADING4;
var paragraphs = getParagraphs();
return paragraphs.filter(function(paragraph) {
return (paragraph.header == searchHeading);
});

function getParagraphs() {
var paragraphs = DocumentApp.getActiveDocument().getBody().getParagraphs();
return paragraphs.map(function(p, index) {
return {
paragraph: p.getText(),
header: p.getHeading(),
id: index
};
});
}


Is there anyway to get the contents of the outline without parsing each paragraph and filtering those whose header matches a specific heading, ideally from an API call?



EDIT: Added getParagraphs()










share|improve this question
























  • I'm sorry for my poor English skill. In order to understand correctly the result you want and the current result, can I ask you about your question? Can you provide about the detail of getParagraphs() and the current result? From your current result, can you also provide the result you want?
    – Tanaike
    Nov 9 at 0:20










  • No problem, I updated the question with the implementation for getParagraphs(). It returns a list of custom paragraph objects. There are the same as google paragrahps but also have an id for their order. This function works fine, but ultimately what I want is an API call to get the contents of a documents outline.
    – Alexsh
    Nov 12 at 16:38










  • Thank you for replying it.
    – Tanaike
    Nov 12 at 23:15













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am able to get the contents of a documents outline by searching all the paragraphs and seeing the heading each paragraph is using. This works but isn't ideal. If I manually remove an item from the outline, it doesn't change the heading of that item to normal. Therefore when I run my code again it'll detect the removed item as still being part of the outline since it's heading matches one used for the outline.



var searchHeading = DocumentApp.ParagraphHeading.HEADING4;
var paragraphs = getParagraphs();
return paragraphs.filter(function(paragraph) {
return (paragraph.header == searchHeading);
});

function getParagraphs() {
var paragraphs = DocumentApp.getActiveDocument().getBody().getParagraphs();
return paragraphs.map(function(p, index) {
return {
paragraph: p.getText(),
header: p.getHeading(),
id: index
};
});
}


Is there anyway to get the contents of the outline without parsing each paragraph and filtering those whose header matches a specific heading, ideally from an API call?



EDIT: Added getParagraphs()










share|improve this question















I am able to get the contents of a documents outline by searching all the paragraphs and seeing the heading each paragraph is using. This works but isn't ideal. If I manually remove an item from the outline, it doesn't change the heading of that item to normal. Therefore when I run my code again it'll detect the removed item as still being part of the outline since it's heading matches one used for the outline.



var searchHeading = DocumentApp.ParagraphHeading.HEADING4;
var paragraphs = getParagraphs();
return paragraphs.filter(function(paragraph) {
return (paragraph.header == searchHeading);
});

function getParagraphs() {
var paragraphs = DocumentApp.getActiveDocument().getBody().getParagraphs();
return paragraphs.map(function(p, index) {
return {
paragraph: p.getText(),
header: p.getHeading(),
id: index
};
});
}


Is there anyway to get the contents of the outline without parsing each paragraph and filtering those whose header matches a specific heading, ideally from an API call?



EDIT: Added getParagraphs()







google-apps-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 16:36

























asked Nov 8 at 16:59









Alexsh

135




135












  • I'm sorry for my poor English skill. In order to understand correctly the result you want and the current result, can I ask you about your question? Can you provide about the detail of getParagraphs() and the current result? From your current result, can you also provide the result you want?
    – Tanaike
    Nov 9 at 0:20










  • No problem, I updated the question with the implementation for getParagraphs(). It returns a list of custom paragraph objects. There are the same as google paragrahps but also have an id for their order. This function works fine, but ultimately what I want is an API call to get the contents of a documents outline.
    – Alexsh
    Nov 12 at 16:38










  • Thank you for replying it.
    – Tanaike
    Nov 12 at 23:15


















  • I'm sorry for my poor English skill. In order to understand correctly the result you want and the current result, can I ask you about your question? Can you provide about the detail of getParagraphs() and the current result? From your current result, can you also provide the result you want?
    – Tanaike
    Nov 9 at 0:20










  • No problem, I updated the question with the implementation for getParagraphs(). It returns a list of custom paragraph objects. There are the same as google paragrahps but also have an id for their order. This function works fine, but ultimately what I want is an API call to get the contents of a documents outline.
    – Alexsh
    Nov 12 at 16:38










  • Thank you for replying it.
    – Tanaike
    Nov 12 at 23:15
















I'm sorry for my poor English skill. In order to understand correctly the result you want and the current result, can I ask you about your question? Can you provide about the detail of getParagraphs() and the current result? From your current result, can you also provide the result you want?
– Tanaike
Nov 9 at 0:20




I'm sorry for my poor English skill. In order to understand correctly the result you want and the current result, can I ask you about your question? Can you provide about the detail of getParagraphs() and the current result? From your current result, can you also provide the result you want?
– Tanaike
Nov 9 at 0:20












No problem, I updated the question with the implementation for getParagraphs(). It returns a list of custom paragraph objects. There are the same as google paragrahps but also have an id for their order. This function works fine, but ultimately what I want is an API call to get the contents of a documents outline.
– Alexsh
Nov 12 at 16:38




No problem, I updated the question with the implementation for getParagraphs(). It returns a list of custom paragraph objects. There are the same as google paragrahps but also have an id for their order. This function works fine, but ultimately what I want is an API call to get the contents of a documents outline.
– Alexsh
Nov 12 at 16:38












Thank you for replying it.
– Tanaike
Nov 12 at 23:15




Thank you for replying it.
– Tanaike
Nov 12 at 23:15

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53212639%2fhow-do-i-get-a-google-apps-script-document-outline-from-the-api%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53212639%2fhow-do-i-get-a-google-apps-script-document-outline-from-the-api%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff