-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modify.replaceText not working properly #73
Comments
I remember some weird issues in the past which could be related to this. PowerPoint's way to store text in xml can be surprisingly complex. Depending on the order of typing letters into a textbox, they eventually might split up in the file: <a:t>{{NAME}</a:t> <a:t>}</a:t> Although I was trying to handle this by You can try a workaround:
This will not make any visible difference, but join the xml elements. In general, it seems as if varying text format inside a textbox can break Good luck on this! |
Maybe it will become clearer if we take a look at /**
* Replace tagged text content within modified shape
*/
static replaceText = (
replaceText: ReplaceText | ReplaceText[],
options?: ReplaceTextOptions,
): ShapeModificationCallback => {
const shapeModCallback = (element: XmlElement): void => {
const replaceTexts = GeneralHelper.arrayify(replaceText);
new TextReplaceHelper(options, element as XmlElement)
.isolateTaggedNodes()
.applyReplacements(replaceTexts);
};
return shapeModCallback;
}; Applied to your code, we could add a few lines to increase readability: const replaceParams = [{
replace: 'NAME',
by: {
text: client.displayName
}
}]
slides.forEach((slide) => {
pres.addSlide("base", slide.number, async(slide) => {
const elements = await slide.getAllTextElementIds();
const shapeModCb = modify.replaceText(replaceParams) as ShapeModificationCallback;
elements.forEach(element => {
slide.modifyElement(element, shapeModCb);
// which equals
// slide.modifyElement(element, [ shapeModCb ]);
})
});
}); For convenience, you can use a single Callback or an array of callbacks. You could also use multiple calls of Later on, your callback(s) will be applied to the element XML: // taken from src/classes/shape.ts
applyCallbacks(
callbacks: ShapeModificationCallback[],
element: XmlElement,
relation?: XmlElement,
): void {
callbacks.forEach((callback) => {
if (typeof callback === 'function') {
try {
callback(element, relation);
} catch (e) {
console.warn(e);
}
}
});
} If I have to handle complex code constructions like the above, it helps to add a few lines and declare a some more The latest version I hope this helps! 😃 |
Aside from that, I'm having a weird issue where modify isn't working. I think this should work, but the modify() doesn't actually replace the text.
Originally posted by @chriscap-fd in #71 (comment)
The text was updated successfully, but these errors were encountered: