How to get formatted text into arrays
Dear experts and helpers,
For my project I import an RTF file and then read the data from it into 3 arrays. This works fine when just using the string contents of the paragraphs. However, the final script should be able to read and replace formatted text...
Why use the intermediate arrays? Because otherwise I need to switch back and forth between two fm-documents (and one may be a book component).
The imported file starts with a number of lines separated into two items by a TAB (» denotes a TAB, in FM \x08)
[[Garneau, 1990 #12]] » [9]
The right item may also be locally formatted text, e.g. [9]
Then follow the same (or smaller) number of paragraphs with formatted text like this:
[9] » D. Garneau, Ed., National Language Support Reference Manual (National language Information Design Guide. Toronto, CDN: IBM National Language Technical Centre, 1990.
Is it possible to replace in the body of the function below the following piece
while(pgf.ObjectValid()) {
pgfText = GetText (pgf, newDoc);
gaBibliography.push(pgfText);
pgf = pgf.NextPgfInFlow;
}
with this
while(pgf.ObjectValid()) {
gaBibliography.push(pgf);
pgf = pgf.NextPgfInFlow;
}
Do I need a special declaration of the array gaBibliography ?
And how to get the right part of the intro lines as formatted thingy into array gaFmtCitsFmt ?
Currently I read into arrays only the 'strings' (function GetText not shown):
var gaFmtCitsRaw = []; // left column in processed RTF
var gaFmtCitsFmt = []; // right column in processed RTF
var gaBibliography= []; // bibliography lines from processed RTF
// filename is something like E:\_DDDprojects\FM+EN-escript\FM-testfiles\BibFM-collected-IEEE.rtf
function ReadFileRTF (fileName) {
var nCits=0, nBib = 0, openParams, openReturnParams, newDoc, pgf, pgfText ;
var TAB = String.fromCharCode(8); // FM has wrong ASCI for TAB
var parts = [];
openParams = GetOpenDefaultParams();
openReturnParams = new PropVals();
newDoc = Open (fileName, openParams, openReturnParams);
pgf = newDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf; // get first pgf in flow
// --- read the temp/formatted citations
while(pgf.ObjectValid()) {
pgfText = GetText (pgf, newDoc);
if (pgfText.substring (0,2) == "[[") { // citation lines start with [[
parts = pgfText.split(TAB); // get the two parts of the line
gaFmtCitsRaw.push (parts[0]); // Push the result onto the global array
gaFmtCitsFmt.push (parts[1]);
pgf = pgf.NextPgfInFlow;
} else { break }
}
// --- read the bibliography
while(pgf.ObjectValid()) { // until end of doc
pgfText = GetText (pgf, newDoc);
gaBibliography.push(pgfText);
pgf = pgf.NextPgfInFlow;
}
newDoc.Close (Constants.FF_CLOSE_MODIFIED);
} // --- end ReadFileRTF
The next questions then will be how to modify Ian Proudfoot's FindAndReplace script to handle formatted text as replacement. IMHO i will need to use copy/paste ...

