The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi all!
We want to strip out some divs that where accidentally added to the body content by the google translate browser extension.
The stripping works great but other macros are broken because the hard-coded indentation within the macro xml that are interpreted as spaces at the beginning of the macro options values.
Is there a way to prevent this automatic modification?
Thanks a lot!
Philipp
def SpaceKey = 'TPFR3';
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import org.jsoup.Jsoup
import org.jsoup.*
import org.jsoup.nodes.*
def pageManager = ComponentLocator.getComponent(PageManager)
def spaceManager = ComponentLocator.getComponent(SpaceManager)
def targetSpace = spaceManager.getSpace(SpaceKey)
pageManager.getPages(targetSpace, true).each { page ->
log.debug "Inspecting page ${page.title}"
def body = page.bodyContent.body
def parsedBody = Jsoup.parse(body)
def macroBody = parsedBody.select("div.gtx-trans-icon")
log.debug "elements:" + macroBody
if (!macroBody.empty) {
log.debug "elements:" + macroBody
pageManager.saveNewVersion(page) { pageObject ->
macroBody.remove()
pageObject.setBodyAsString(parsedBody.toString())
}
}
Modified with spaces and indents
Orginal
Broken macro
I found the answer: prettyPrint has to be disabled.
paersedBody.outputSettings.prettyPrint(false)
Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.