This may catch the unwary as it will produce unneeded new notes for the first two ‘header’ lines of the data in the source $Text, i.e. the lines…
|Keywords|Explanation|
|---|---|
You could either add a test inside the loop:
$Text.eachLine(x) {
if(!x.beginsWith("|Keywords|") & !x.beginsWith("|---|"){
x.expect ......
Simpler perhaps is to stream parse the $Text to the end of the preamble, then iterate the result:
var:string vData;
var:string vNoteName;
var:string vNoteText;
vData = $Text.skipTo("|---|---|");
vData.eachLine(x) {
x.expect('|').captureTo('|',"vNoteName").captureTo('|',"vNoteText");
var:string vPath=create("/container", vNoteName);
$Text(vPath)=vNoteText;
};
Notes:
- Observe the subtle difference between String.skipTo(matchStr) and String.expect(matchStr). The first simply moves the stream cursor to the position after the matched literal string matchStr. The latter only advances the stream if a match is made, if no match the cursor stays put.
- This means
.beginsWith()
cannot test matchStr is at the start of a line as a value of^|
would looks for a literal^
character at the start of the line.
- This means
- The matchStr argument taken by the string operators
.beginsWith()
,.captureTo()
,.endsWith()
and.skipto()
cannot be a regular expression. It must be a literal string.
Here is a text TBX for the above: process-terms-01.tbx (200.3 KB). Run stamp “Process terms” on note “Source text”. First, You may want to delete the container “Terms” and its contents so that you see the notes actually being made by the stamp.