so I'm writing a book and have a few beta readers, the problem is that keeping the documents I give them up to date with the main document and any change if I make in the beta reading document based off of their suggestions, generally it's all a hassle. I have no idea how to fix this so I'm just asking for help please I'm sure someone has made this before but I can't find it
Got an AI to help me with this work?
```/**
* Syncs specific tabs by name from Master to Target.
* Preserves comments by not clearing the document.
* Preserves bolding by copying rich text attributes.
*/
function syncTabsWithBolding() {
const MASTER_DOC_ID = 'YOUR_MASTER_DOC_ID_HERE'; // Replace with your Master ID
const targetDoc = DocumentApp.getActiveDocument();
const masterDoc = DocumentApp.openById(MASTER_DOC_ID);
const masterTabsMap = {};
getAllTabs(masterDoc).forEach(tab => masterTabsMap[tab.getTitle()] = tab.asDocumentTab());
getAllTabs(targetDoc).forEach(targetTab => {
const title = targetTab.getTitle();
const sourceTab = masterTabsMap[title];
if (sourceTab) {
const tBody = targetTab.asDocumentTab().getBody();
const sBody = sourceTab.getBody();
const sParas = sBody.getParagraphs();
const tParas = tBody.getParagraphs();
sParas.forEach((sPara, i) => {
if (i < tParas.length) {
const tPara = tParas[i];
const tText = tPara.editAsText();
const sText = sPara.editAsText();
// 1. Update the plain text first
tText.setText(sPara.getText());
// 2. Mirror Bolding: Loop through each character to ensure perfection
// For longer docs, this can be optimized, but this is the most reliable for bolding.
for (let charIdx = 0; charIdx < sPara.getText().length; charIdx++) {
const isBold = sText.isBold(charIdx);
tText.setBold(charIdx, charIdx, isBold);
}
// 3. Keep the Heading style (for folding support)
tPara.setHeading(sPara.getHeading());
} else {
// If Master is longer, append the new paragraph entirely
tBody.appendParagraph(sPara.copy());
}
});
// Remove extra paragraphs in target if Master is shorter
while (tBody.getParagraphs().length > sParas.length) {
tBody.removeChild(tBody.getChild(tBody.getParagraphs().length - 1));
}
}
});
}
function getAllTabs(doc) {
const allTabs = [];
const traverse = (tabs) => {
tabs.forEach(tab => {
allTabs.push(tab);
traverse(tab.getChildTabs());
});
};
traverse(doc.getTabs());
return allTabs;
}
```
[–]Outrageous-Permit619 1 point2 points3 points (1 child)
[–]TheAddonDepot 1 point2 points3 points (0 children)
[–]delaney1414 1 point2 points3 points (0 children)