Script for getting footnotes into an HTML document

Help with writing and running scripts

Script for getting footnotes into an HTML document

Postby fvgfvg » Mon May 07, 2012 6:31 am

I have many texts containing strings of type:

A2B2C2D2E2F2G
A2B2C2D2E2F2G
A2B2C2D2E2F2G

Would anyone know how to write a regex that will increment the integer during each iteration?

like so:

A2B2C2D2E2F2G
A3B3C3D3E3F3G
A4B4C4D4E4F4G
...
A329B329C329D329E329F329G
etc.

I'd be most grateful for help!
best,
fvg
fvgfvg
Newbie
 
Posts: 8
Joined: Thu Apr 26, 2012 9:49 am

Re: Script for getting footnotes into an HTML document

Postby Mofi » Tue May 08, 2012 6:23 am

I used the first script posted at How to insert incremental numbers after specific text to create this script making the job for your example. This topic was the first one in the forum search results.

Code: Select all
if (UltraEdit.document.length > 0) {
   UltraEdit.insertMode();
   UltraEdit.columnModeOff();
   UltraEdit.activeDocument.hexOff();
   UltraEdit.perlReOn();
   var nNumber = 1;
   var sNumber = "1";
   UltraEdit.activeDocument.top();
   UltraEdit.activeDocument.findReplace.mode=0;
   UltraEdit.activeDocument.findReplace.matchCase=true;
   UltraEdit.activeDocument.findReplace.matchWord=false;
   UltraEdit.activeDocument.findReplace.regExp=true;
   UltraEdit.activeDocument.findReplace.searchDown=true;
   UltraEdit.activeDocument.findReplace.searchInColumn=false;
   UltraEdit.activeDocument.findReplace.preserveCase=false;
   UltraEdit.activeDocument.findReplace.replaceAll=false;
   UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
   while (UltraEdit.activeDocument.findReplace.replace("A\\d+","A"+sNumber)) {
      UltraEdit.activeDocument.findReplace.replace("B\\d+","B"+sNumber);
      UltraEdit.activeDocument.findReplace.replace("C\\d+","C"+sNumber);
      UltraEdit.activeDocument.findReplace.replace("D\\d+","D"+sNumber);
      UltraEdit.activeDocument.findReplace.replace("E\\d+","E"+sNumber);
      UltraEdit.activeDocument.findReplace.replace("F\\d+","F"+sNumber);
      nNumber++;
      sNumber = nNumber.toString();
   }
}

It is not very smart, but produces the correct result. However, here is another script very similar using a tagged regular expression Replace in a loop to do the same line by line where it does not matter which characters are before the numbers to replace. I use the UltraEdit regular expression engine in this script because search and replace strings are shorter. The Perl regular expression engine requires backslashes in the expressions which is an escape character in Javascript. Therefore every backslash in the Perl regular expression search and replace strings must be escaped with another backslash. That would make the Perl regular expressions longer and harder to read.

Code: Select all
if (UltraEdit.document.length > 0) {
   UltraEdit.insertMode();
   UltraEdit.columnModeOff();
   UltraEdit.activeDocument.hexOff();
   UltraEdit.ueReOn();
   UltraEdit.activeDocument.top();
   UltraEdit.activeDocument.findReplace.mode=0;
   UltraEdit.activeDocument.findReplace.matchCase=true;
   UltraEdit.activeDocument.findReplace.matchWord=false;
   UltraEdit.activeDocument.findReplace.regExp=true;
   UltraEdit.activeDocument.findReplace.searchDown=true;
   UltraEdit.activeDocument.findReplace.searchInColumn=false;
   UltraEdit.activeDocument.findReplace.preserveCase=false;
   UltraEdit.activeDocument.findReplace.replaceAll=false;
   UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
   var nNumber = 0;
   do {
      nNumber++;
      var sNumber = nNumber.toString();
      var sReplace = "^1"+sNumber+"^2"+sNumber+"^3"+sNumber+"^4"+sNumber+"^5"+sNumber+"^6"+sNumber;
   }
   while (UltraEdit.activeDocument.findReplace.replace("%^([~0-9]+^)[0-9]+^([~0-9]+^)[0-9]+^([~0-9]+^)[0-9]+^([~0-9]+^)[0-9]+^([~0-9]+^)[0-9]+^([~0-9]+^)[0-9]+",sReplace));
}
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Script for getting footnotes into an HTML document

Postby fvgfvg » Tue May 08, 2012 6:48 am

Thank you Mofi. Your'e a real help ...
fvgfvg
Newbie
 
Posts: 8
Joined: Thu Apr 26, 2012 9:49 am

Re: Script for getting footnotes into an HTML document

Postby fvgfvg » Wed May 09, 2012 2:55 pm

With Mofi's help I've been making real progress. With the script as I've modified it a bit,
Code: Select all
if (UltraEdit.document.length > 0) {
   UltraEdit.insertMode();
   UltraEdit.columnModeOff();
   UltraEdit.activeDocument.hexOff();
   UltraEdit.perlReOn();
   // Footnotes/endnotes to start with this number: (insert here!)
   var nNumber = 1;
   sNumber = nNumber.toString();
   UltraEdit.activeDocument.top();
   UltraEdit.activeDocument.findReplace.mode=0;
   UltraEdit.activeDocument.findReplace.matchCase=true;
   UltraEdit.activeDocument.findReplace.matchWord=false;
   UltraEdit.activeDocument.findReplace.regExp=true;
   UltraEdit.activeDocument.findReplace.searchDown=true;
   UltraEdit.activeDocument.findReplace.searchInColumn=false;
   UltraEdit.activeDocument.findReplace.preserveCase=false;
   UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
   UltraEdit.activeDocument.findReplace.replaceAll=true;
   UltraEdit.activeDocument.findReplace.replace("<<","~A1~B1~C1~D1~E1~F1~G");
   UltraEdit.activeDocument.top();
   UltraEdit.activeDocument.findReplace.replaceAll=false;
   while (UltraEdit.activeDocument.findReplace.replace("~A\\d+","~A"+sNumber)) {
      UltraEdit.activeDocument.findReplace.replace("~B\\d+","~B"+sNumber);
      UltraEdit.activeDocument.findReplace.replace("~C\\d+","~C"+sNumber);
      UltraEdit.activeDocument.findReplace.replace("~D\\d+","~D"+sNumber);
      UltraEdit.activeDocument.findReplace.replace("~E\\d+","~E"+sNumber);
      UltraEdit.activeDocument.findReplace.replace("~F\\d+","~F"+sNumber);
      UltraEdit.activeDocument.findReplace.replace("~G\\d+","~G"+sNumber);
      nNumber++;
      sNumber = nNumber.toString();
   }
    UltraEdit.activeDocument.findReplace.replaceAll=true;
    UltraEdit.activeDocument.top();
//      ALL HTML '"' MUST BE QUOTED OUT!!!!
//      fn-snippet A:     <a NAME="BACK_
//      fn-snippet B:     \"></a><a href=\"fvg_hbhm_fn.html#endnote_
//      fn-snippet C:     \"><sup>[
//      fn-snippet D:     ]</sup></a>!<a NAME=\"endnote_
//      fn-snippet E:     \"><p><a HREF=\"fvg_hbhm_text1.html#BACK_
//      fn-snippet F:     \">[
//      fn-snippet G:     ]</a>
    UltraEdit.activeDocument.findReplace.replace("~A","<a NAME=\"BACK_");
    UltraEdit.activeDocument.findReplace.replace("~B","\"></a><a href=\"fvg_hbhm_fn.html#endnote_");
    UltraEdit.activeDocument.findReplace.replace("~C","\"><sup>[");
    UltraEdit.activeDocument.findReplace.replace("~D","]</sup></a>!<a NAME=\"endnote_");
    UltraEdit.activeDocument.findReplace.replace("~E","\"><p><a HREF=\"fvg_hbhm_text1.html#BACK_");
    UltraEdit.activeDocument.findReplace.replace("~F","\">[");
    UltraEdit.activeDocument.findReplace.replace("~G","]</a>");
 //     todo:  1) copy file to 'file.tmp'
 //            2) find the fn's in FILE.TMP
 //            3) delete the fn's in current file.
 //            4) insert output file content at end of current file.
   
}

I've now got from here:

Code: Select all
this is text this is text this is text<<endnote endnote endnote>>
this is text this is text this is text this is text this is text
this is<<endnote endnote endnote>> text this is text this is text
this is text<<endnote endnote endnote>> this is text this is text
this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text<<endnote endnote
endnote>> this is text this is text this is text this is text this is text this is<<endnote endnote endnote>> text this is text this is text this is text<<endnote
endnote endnote>> this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text
this is text this is text this is text this is text<<endnote endnote endnote>> this is text this is text this is text this is text<<endnote endnote endnote>> this is text this is text this is text this is text<<endnote endnote endnote>> this is text this is text this is text this is text<<endnote endnote endnote>> this is text

to here:

Code: Select all
this is text this is text this is text<a NAME="BACK_1"></a><a href="fvg_hbhm_fn.html#endnote_1"><sup>[1]</sup></a>!<a NAME="endnote_1"><p><a HREF="fvg_hbhm_text1.html#BACK_1">[1]</a>endnote endnote endnote>>
this is text this is text this is text this is text this is text
this is<a NAME="BACK_2"></a><a href="fvg_hbhm_fn.html#endnote_2"><sup>[2]</sup></a>!<a NAME="endnote_2"><p><a HREF="fvg_hbhm_text1.html#BACK_2">[2]</a>endnote endnote endnote>> text this is text this is text
this is text<a NAME="BACK_3"></a><a href="fvg_hbhm_fn.html#endnote_3"><sup>[3]</sup></a>!<a NAME="endnote_3"><p><a HREF="fvg_hbhm_text1.html#BACK_3">[3]</a>endnote endnote endnote>> this is text this is text
this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text<a NAME="BACK_4"></a><a href="fvg_hbhm_fn.html#endnote_4"><sup>[4]</sup></a>!<a NAME="endnote_4"><p><a HREF="fvg_hbhm_text1.html#BACK_4">[4]</a>endnote endnote
endnote>> this is text this is text this is text this is text this is text this is<a NAME="BACK_5"></a><a href="fvg_hbhm_fn.html#endnote_5"><sup>[5]</sup></a>!<a NAME="endnote_5"><p><a HREF="fvg_hbhm_text1.html#BACK_5">[5]</a>endnote endnote endnote>> text this is text this is text this is text<a NAME="BACK_6"></a><a href="fvg_hbhm_fn.html#endnote_6"><sup>[6]</sup></a>!<a NAME="endnote_6"><p><a HREF="fvg_hbhm_text1.html#BACK_6">[6]</a>endnote
endnote endnote>> this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text
this is text this is text this is text this is text<a NAME="BACK_7"></a><a href="fvg_hbhm_fn.html#endnote_7"><sup>[7]</sup></a>!<a NAME="endnote_7"><p><a HREF="fvg_hbhm_text1.html#BACK_7">[7]</a>endnote endnote endnote>> this is text this is text this is text this is text<a NAME="BACK_8"></a><a href="fvg_hbhm_fn.html#endnote_8"><sup>[8]</sup></a>!<a NAME="endnote_8"><p><a HREF="fvg_hbhm_text1.html#BACK_8">[8]</a>endnote endnote endnote>> this is text this is text this is text this is text<a NAME="BACK_9"></a><a href="fvg_hbhm_fn.html#endnote_9"><sup>[9]</sup></a>!<a NAME="endnote_9"><p><a HREF="fvg_hbhm_text1.html#BACK_9">[9]</a>endnote endnote endnote>> this is text this is text this is text this is text<a NAME="BACK_10"></a><a href="fvg_hbhm_fn.html#endnote_10"><sup>[10]</sup></a>!<a NAME="endnote_10"><p><a HREF="fvg_hbhm_text1.html#BACK_10">[10]</a>endnote endnote endnote>> this is text

Which nicely renders to the numbered footnotes that I'm trying to generate.

What has got me completely stumped is two things: the regex to match the footnote (starting with:
!<a NAME="endnote_
and ending with:
>>

I thought this would do it:

Code: Select all
UltraEdit.activeDocument.findReplace.replace("!<a NAME=\"endnote[ !$A-Z0-9._%+-]+>>","XXXX");

Or this:

Code: Select all
UltraEdit.activeDocument.findReplace.replace("!<a NAME=\"!<a NAME=\"endnote_.*\>\>","XXXX");

(with or without the quoting "\"s) but no luck, no match. (Some, but not all the matched strings contain <CR><LF>s; the XXXX is just temporary, till I figure out what to do when it finally works.) I've been working on this for days. (I've bought a RegexBuddy, but it hasn't arrived yet.) Beginner's travails...

Secondly, I can't work out how to move these matched strings - once the regex does work - to the clipboard, to another file, or - preferably - to the end of the current file. (I've been reading through the corresponding posts elsewhere on this list, but it's double Dutch to me...) (Bit of irony there, since I speak Dutch perfectly well - wish I could say the same thing about JS!)
I'm learning a lot, but any help would be really appreciated...
fvg
fvgfvg
Newbie
 
Posts: 8
Joined: Thu Apr 26, 2012 9:49 am

Re: Script for getting footnotes into an HTML document

Postby Mofi » Thu May 10, 2012 12:47 am

Look on first endnote string which should be found by your expressions:

!<a NAME="endnote_1"><p><a HREF="fvg_hbhm_text1.html#BACK_1">[1]</a>endnote endnote endnote>>

Now take a look on expression [ !$A-Z0-9._%+-]+. What about the characters "#[]/<>= which also exist all in the string to find but are missing in the character class definition in the expression?

The second expression is better, but does not work well because the expression does not include line terminating characters and is greedy. What you need is:

UltraEdit.activeDocument.findReplace.replace("(?s)!<a NAME=\"endnote.+?>>","XXXX");

For an explanation of (?s) see "." in Perl regular expressions doesn't include CRLFs?

The expressions .+ is by default a greedy expression. That means it matches as much as possible. So it does not stop on first occurrence of >> after string !<a NAME="endnote, it stops left to last occurrence of >> which is not what you want as this would result in selecting multiple endnotes with everything between. With .+? the expression becomes non greedy and now matching any character stops left to first occurrence of >>.


A string found with command UltraEdit.activeDocument.findReplace.find() is automatically also selected. You have 3 choices to run a string collecting loop.

Version 1: Using a user clipboard and command Copy & Append.

Code: Select all
// Use user clipboard 9 instead of Windows clipboard.
// This version should be used if Unicode characters are matched too.
UltraEdit.selectClipboard(9);
UltraEdit.clearClipboard();
UltraEdit.activeDocument.top();
while(UltraEdit.activeDocument.findReplace.find("...whatever...")) {
   UltraEdit.activeDocument.copyAppend();
   UltraEdit.clipboardContent += "\r\n";
}
UltraEdit.activeDocument.bottom();
UltraEdit.activeDocument.paste();
UltraEdit.clearClipboard();
UltraEdit.selectClipboard(0);


Version 2: Using a user clipboard and directly append a found string.

The second version is the same as above with the difference that instead of UltraEdit.activeDocument.copyAppend(); the following code is used:

Code: Select all
   UltraEdit.clipboardContent += UltraEdit.activeDocument.selection;

This is not working for Unicode strings. Therefore there is just a disadvantage and no advantage in comparison to first version. I have posted this version just for completness.

Version 3: Collecting found strings in a dynamic Javascript string variable.

Code: Select all
var sFoundStrings = "";
UltraEdit.activeDocument.top();
while(UltraEdit.activeDocument.findReplace.find("...whatever...")) {
   sFoundStrings += UltraEdit.activeDocument.selection;
   sFoundStrings += "\r\n";
}
UltraEdit.activeDocument.write(sFoundStrings);

This version does not work for Unicode strings. And as I found out once without knowing the reason this method is much slower than using the first version with using the clipboard for large files.

Please note that if the Find is a Perl regular expression find you might need as last command within while loop UltraEdit.activeDocument.cancelSelect(); to avoid and endless loop finding last occurrence again and again.
With UE or Unix regular expressions finds or with a non regular expression find this command is not needed.

BTW: Your HTML code is invalid. You have block element <p> embedded in inline element <a>.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Script for getting footnotes into an HTML document

Postby fvgfvg » Thu May 10, 2012 6:46 am

That worked like a charm, with accolades to Mofi!
This script now correctly collects all footnotes from a text and moves them to the bottom of the file:
From this:
Code: Select all
this is text this is text this is text<<endnote endnote endnote>>
this is text this is text this is text this is text this is text
this is<<endnote endnote endnote>> text this is text this is text
this is text<<endnote endnote endnote>> this is text this is text
this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text<<endnote endnote <CR>
endnote>> this is text this is text this is text this is text this is text this is<<endnote endnote endnote>> text this is text this is text this is text<<endnote <CR>
endnote endnote>> this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text
this is text this is text this is text this is text<<endnote endnote endnote>> this is text this is text this is text this is text<<endnote endnote endnote>> this is text this is text this is text this is text<<endnote endnote endnote>> this is text this is text this is text this is text<<endnote endnote endnote>> this is text

to this:
Code: Select all
this is text this is text this is text<a NAME="BACK_1"></a><a href="fvg_hbhm_fn.html#endnote_1"><sup>[1]</sup></a>
this is text this is text this is text this is text this is text
this is<a NAME="BACK_2"></a><a href="fvg_hbhm_fn.html#endnote_2"><sup>[2]</sup></a> text this is text this is text
this is text<a NAME="BACK_3"></a><a href="fvg_hbhm_fn.html#endnote_3"><sup>[3]</sup></a> this is text this is text
this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text<a NAME="BACK_4"></a><a href="fvg_hbhm_fn.html#endnote_4"><sup>[4]</sup></a> this is text this is text this is text this is text this is text this is<a NAME="BACK_5"></a><a href="fvg_hbhm_fn.html#endnote_5"><sup>[5]</sup></a> text this is text this is text this is text<a NAME="BACK_6"></a><a href="fvg_hbhm_fn.html#endnote_6"><sup>[6]</sup></a> this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text
this is text this is text this is text this is text<a NAME="BACK_7"></a><a href="fvg_hbhm_fn.html#endnote_7"><sup>[7]</sup></a> this is text this is text this is text this is text<a NAME="BACK_8"></a><a href="fvg_hbhm_fn.html#endnote_8"><sup>[8]</sup></a> this is text this is text this is text this is text<a NAME="BACK_9"></a><a href="fvg_hbhm_fn.html#endnote_9"><sup>[9]</sup></a> this is text this is text this is text this is text<a NAME="BACK_10"></a><a href="fvg_hbhm_fn.html#endnote_10"><sup>[10]</sup></a> this is text <a NAME="endnote_1"><p><a HREF="fvg_hbhm_text1.html#BACK_1">[1]</a>endnote endnote endnote
<a NAME="endnote_2"><p><a HREF="fvg_hbhm_text1.html#BACK_2">[2]</a>endnote endnote endnote
<a NAME="endnote_3"><p><a HREF="fvg_hbhm_text1.html#BACK_3">[3]</a>endnote endnote endnote
<a NAME="endnote_4"><p><a HREF="fvg_hbhm_text1.html#BACK_4">[4]</a>endnote endnote <CR>
endnote
<a NAME="endnote_5"><p><a HREF="fvg_hbhm_text1.html#BACK_5">[5]</a>endnote endnote endnote
<a NAME="endnote_6"><p><a HREF="fvg_hbhm_text1.html#BACK_6">[6]</a>endnote <CR>
endnote endnote
<a NAME="endnote_7"><p><a HREF="fvg_hbhm_text1.html#BACK_7">[7]</a>endnote endnote endnote
<a NAME="endnote_8"><p><a HREF="fvg_hbhm_text1.html#BACK_8">[8]</a>endnote endnote endnote
<a NAME="endnote_9"><p><a HREF="fvg_hbhm_text1.html#BACK_9">[9]</a>endnote endnote endnote
<a NAME="endnote_10"><p><a HREF="fvg_hbhm_text1.html#BACK_10">[10]</a>endnote endnote endnote

(Which correctly renders in my browser. I'll tweak that HTML later, Mofi, soon as I've understood what's wrong with it..).
But there will be other people out there who need to use footnotes on a web document, so here is the script ... see my next post for improved version.
fvgfvg
Newbie
 
Posts: 8
Joined: Thu Apr 26, 2012 9:49 am

Re: Script for getting footnotes into an HTML document

Postby Mofi » Thu May 10, 2012 9:52 am

Well, you have used once fvg_hbhm_fn.html and once fvg_hbhm_text1.html. I don't think that this is a good idea if text and footnotes are in same HTML file.

Better would be the output:

Code: Select all
this is text this is text this is text<a href="#endnote_1" name="BACK_1"><sup>[1]</sup></a>
this is text this is text this is text this is text this is text
this is<a href="#endnote_2" name="BACK_2"><sup>[2]</sup></a> text this is text this is text
this is text<a href="#endnote_3" name="BACK_3"><sup>[3]</sup></a> this is text this is text
this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text<a href="#endnote_4" name="BACK_4"><sup>[4]</sup></a> this is text this is text this is text this is text this is text this is<a href="#endnote_5" name="BACK_5"><sup>[5]</sup></a> text this is text this is text this is text<a href="#endnote_6" name="BACK_6"><sup>[6]</sup></a> this is text this is text this is text this is text this is text this is text this is text this is text this is text this is text
this is text this is text this is text this is text<a href="#endnote_7" name="BACK_7"><sup>[7]</sup></a> this is text this is text this is text this is text<a href="#endnote_8" name="BACK_8"><sup>[8]</sup></a> this is text this is text this is text this is text<a href="#endnote_9" name="BACK_9"><sup>[9]</sup></a> this is text this is text this is text this is text<a href="#endnote_10" name="BACK_10"><sup>[10]</sup></a> this is text
<p><a href="#BACK_1" name="endnote_1">[1]</a>endnote endnote endnote</p>
<p><a href="#BACK_2" name="endnote_2">[2]</a>endnote endnote endnote</p>
<p><a href="#BACK_3" name="endnote_3">[3]</a>endnote endnote endnote</p>
<p><a href="#BACK_4" name="endnote_4">[4]</a>endnote endnote <CR>
endnote</p>
<p><a href="#BACK_5" name="endnote_5">[5]</a>endnote endnote endnote</p>
<p><a href="#BACK_6" name="endnote_6">[6]</a>endnote <CR>
endnote endnote</p>
<p><a href="#BACK_7" name="endnote_7">[7]</a>endnote endnote endnote</p>
<p><a href="#BACK_8" name="endnote_8">[8]</a>endnote endnote endnote</p>
<p><a href="#BACK_9" name="endnote_9">[9]</a>endnote endnote endnote</p>
<p><a href="#BACK_10" name="endnote_10">[10]</a>endnote endnote endnote</p>

NAME and HREF are both attributes of inline element A. Both attributes can be used in same element instance. There is no need to have two instances of A element, one with NAME attribute and another with HREF attribute. According to HTML standard A elements with no data (= nothing between <A> and </A>) should be avoided and can be always avoided. If an anchor is needed without being at same time also a hyperlink, the universal attribute ID can be used in any element instead of using <A NAME="..."></A>.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Script for getting footnotes into an HTML document

Postby fvgfvg » Sat May 12, 2012 3:04 am

Right, got it.. Superfluous </a><a>'s deleted, link/anchor sequence reversed. (My guess is, that's not strictly necessary?)
(My original code was intended for use with long web documents, consisting of different chapters, with the endnotes all accumulating into a single, separate, ENDNOTEFILE.html. That's how the publishers usually want it.)
Code: Select all
if (UltraEdit.document.length > 0) {
   UltraEdit.insertMode();
   UltraEdit.columnModeOff();
   UltraEdit.activeDocument.hexOff();
     //UltraEdit.ueReOn();     // UltraEdit
     //UltraEdit.unixReOn();   // Unix
   UltraEdit.perlReOn();       // Perl
     // Change variable nNumber if first Footnote is to be > 1:
   var nNumber = 1;
   sNumber = nNumber.toString();
   UltraEdit.activeDocument.top();
   UltraEdit.activeDocument.findReplace.mode=0;
   UltraEdit.activeDocument.findReplace.matchCase=true;
   UltraEdit.activeDocument.findReplace.matchWord=false;
   UltraEdit.activeDocument.findReplace.regExp=true;
   UltraEdit.activeDocument.findReplace.searchDown=true;
   UltraEdit.activeDocument.findReplace.searchInColumn=false;
   UltraEdit.activeDocument.findReplace.preserveCase=false;
   UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
   UltraEdit.activeDocument.findReplace.replaceAll=true;
   UltraEdit.activeDocument.findReplace.replace("<<","~A1~B1~C1~D1~E1~F1~G");
   UltraEdit.activeDocument.top();
   UltraEdit.activeDocument.findReplace.replaceAll=false;
   while (UltraEdit.activeDocument.findReplace.replace("~A\\d+","~A"+sNumber)) {
      UltraEdit.activeDocument.findReplace.replace("~B\\d+","~B"+sNumber);
      UltraEdit.activeDocument.findReplace.replace("~C\\d+","~C"+sNumber);
      UltraEdit.activeDocument.findReplace.replace("~D\\d+","~D"+sNumber);
      UltraEdit.activeDocument.findReplace.replace("~E\\d+","~E"+sNumber);
      UltraEdit.activeDocument.findReplace.replace("~F\\d+","~F"+sNumber);
      UltraEdit.activeDocument.findReplace.replace("~G\\d+","~G"+sNumber);
      nNumber++;
      sNumber = nNumber.toString();
   }
    UltraEdit.activeDocument.findReplace.replaceAll=true;
    UltraEdit.activeDocument.top();
//  full string:  <a href=\"endnote_x\" name=\"BACK_x\"><sup>[x]</sup></a>
//  full string:  <p><a NAME=\"endnote_x\" HREF=\"BACK_x\">[x]</a>
//      ALL HTML '"' MUST BE QUOTED OUT!!!!
//          snippetA:   <a href=\"endnote_
//          snippetB:   \" name=\"BACK_
//          snippetC:   \"><sup>[
//          snippetD:   ]</sup></a><p><a NAME=\"endnote_
    /       snippetE:   \" HREF=\"BACK_
//          snippetF:   \">[
//          snippetG:   ]</a> 
    UltraEdit.activeDocument.findReplace.replace("~A","<a href=\"endnote_");
    UltraEdit.activeDocument.findReplace.replace("~B","\" name=\"BACK_");
    UltraEdit.activeDocument.findReplace.replace("~C","\"><sup>[");
    UltraEdit.activeDocument.findReplace.replace("~D","]</sup></a><p><a NAME=\"endnote_");
    UltraEdit.activeDocument.findReplace.replace("~E","\" HREF=\"BACK_");
    UltraEdit.activeDocument.findReplace.replace("~F","\">[");
    UltraEdit.activeDocument.findReplace.replace("~G","]</a>");
    UltraEdit.selectClipboard(9);
    UltraEdit.clearClipboard();
    UltraEdit.activeDocument.top();
    while(UltraEdit.activeDocument.findReplace.find("(?s)<p><a NAME=\"endnote.+?>>")) {
      UltraEdit.activeDocument.copyAppend();
      UltraEdit.clipboardContent += "\r\n";
    }                                   // <---END OF WHILE! (DON'T DELETE)
    UltraEdit.activeDocument.top();
    UltraEdit.activeDocument.findReplace.replace("(?s)<p><a NAME=\"endnote.+?>>","");
    UltraEdit.activeDocument.bottom();
    UltraEdit.activeDocument.paste();
    UltraEdit.clearClipboard();
    UltraEdit.selectClipboard(0);
    UltraEdit.activeDocument.top();
    UltraEdit.activeDocument.findReplace.replace(">>","</p>");
 
}    // <---END OF "IF" IN LINE 1! (DON'T DELETE)

// EOF  (With thanks to Mofi!)
fvgfvg
Newbie
 
Posts: 8
Joined: Thu Apr 26, 2012 9:49 am


Return to Scripts