// -*- ASCII:EDT -*- // HTMLtoc.edt // (schlicht 20010421) // automatically generates // a table of contents // with hyperlinks and // correct indentation levels ///////////////////////////// // Change to "UL" if you want. Assign("List","OL"); // Change the header, if you want: LetReg(7,"

Table of Contents

%\<%$('List');>"); SaveFind; SetFindTextSelect(1); SetSearchCurrentDoc; SetSearchCyclic(0); SetSearchEntire(1); SetSearchForward(1); SetRegEx(1); SetSearchInline(0); SetSearchCaseSensitive(0); SetNotFoundNotify(0); SearchReset; // Change this if necessary: //// Two lines maximum (much faster, might miss headers): SetFindStr("\*@{>}*\(0*\)\"); //// Three lines maximum: //SetFindStr("\*@{>}*@{>}*\(0*\)\"); //// Four lines maximum (finds more headers, very slow): //SetFindStr("\*@{>}*@{>}*@{>}*\(0*\)\"); // Ready... LetReg(0,""); LetRegNum(9,1); Mark(0); BeginGroup; CMD("Go To Beginning Of File"); // Go: Loop(!`> SetOK(1);> IfFound(> !"GetSel(0,0);> CMD('Delete');> LetReg(3,'%!0');> // Get the header level (it's the third letter): ExtractByIndex(8,'%!0',2,2);> SetOK(1);> // remove tags inside the header: Loop(!'> FindInString(''%!0'',''\<*\>'',1,2,0001,0);> IfOK(!''ReplaceInString(|%!0|,||,%!1,%!2,0,0);'',> ''Stop;'');> ');> SetOK(1);> // remove line breaks: Loop(!'> FindInString(''%!0'',''>'',1,2,0001,0);> IfOK(!''> ReplaceInString(|%!0|,| |,%!1,%!2,0,0);'',> ''Stop;'');> ');> // remove white space: FormatString('%!0',0,'trimboth');> // put an anchor in front of the header: CMD('Go To Beginning Of Line');> Ins('%!3');> CMD('Go To End Of Line');> // start a new list, if the level increased: Loop(> !'IfNum(%!9,%!8,''<'',> !''LetReg(7,|%!7%\<%$(||List||);>|);> LetRegNum(9,%!9+1);'',> ''Stop;'');> ');> // close the list, if the level decreased: Loop(> !'IfNum(%!9,%!8,''>'',> !''LetReg(7,|%!7%\|);> LetRegNum(9,%!9-1);'',> ''Stop;'');> ');> // append to the toc in Reg. %!7: LetReg(7,'%!7%\
  • %!0
  • ');> ",> "Stop;");> `); Goto(0); // close all lists: Loop(!`IfNum(%!9,0,'=','Stop;',> !'LetReg(7,''%!7%\'');> LetRegNum(9,%!9-1);');`); // and insert the toc: Ins('%!7'); RestoreFind; EndGroup; End; ///////////////////////////////// // this macro produces a // table of contents of all //

    Headers

    // // The TOC will be inserted at the position // of the cursor when you start the macro. // // The macro will miss headers, which span // over more than three lines: //

    like // this // header //

    // If you want you can increase the // maximum number of lines by changing // the SetFindStr(); above. // Note, that the macro will become // much slower with every line. // Unwrapping your text before running // this macro might also be good idea. // // Another (unlikely) error will occur // in the following situation: //

    Header

    // The toc will have this as: // 3. Header comment--> // // If you prefer unordered lists, // you can easily change this in the first line. // // R Schlicht ///////////////////////////////// $Id: HTMLtoc.edt,v 1.1 2001-11-02 17:02:22+01 standard Exp standard $