An issue with soft returns embedding before paragraph tags in Structured framemaker 22
When importing xml into Structured FrameMaker 22, a soft return is embedded before the paragraph tag, pushing heading to the next line.
It should look like this:
In the xml xml:space="preserve" has been added because a tag is included in the xml:
<mainhead xml:space="preserve">Average annual total returns (%) <emphasis role="submainhead">(See important legal information)</emphasis></mainhead>
If I remove xml:space="preserve" , it eliminates the soft return but it does not recognize the tag, so the tag is not applied.
Microsoft CoPilot created a script to remove these soft returns, but it is not working when I run it.
Any help resolving this will be appreciated.
Here is the script:
#target framemaker
function removeSoftReturnsInMainhead() {
var doc = app.ActiveDoc;
if (!doc.ObjectValid()) {
alert("No active document.");
return;
}
var pgf = doc.FirstPgfInDoc;
var count = 0;
while (pgf.ObjectValid()) {
if (pgf.Element.ObjectValid() && pgf.Element.GI === "mainhead") {
var tr = new TextRange();
tr.beg.obj = pgf;
tr.beg.offset = 0;
tr.end.obj = pgf;
tr.end.offset = Constants.FV_OBJ_END_OFFSET;
var text = doc.GetText(tr);
if (text && text.indexOf("\r") !== -1) {
// Clean up soft returns
var cleaned = text
.replace(/\r|\n/g, " ")
.replace(/\s+/g, " ");
doc.SetText(tr, cleaned);
count++;
}
}
pgf = pgf.NextPgfInDoc;
}
alert("Done. Updated paragraphs: " + count);
}
removeSoftReturnsInMainhead();
