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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.