source = '' read,'* Enter Source name: ',source break_file,source,aa,ab,ac,ad,ae outname = ac ; read in the source .html file ;if n_elements(qq) lt 10 then begin print,'** Reading Source file: ',source qq = rd_tfile(source) help,qq ;endif else box_message,'*** Set qq=0 to force a Read ***' nl = n_elements(qq) print,' ' ; get TtH version the info embedded at the start pt2h = strpos(qq(2),'TtH ')+4 t2h_ver = strmid(qq(2),pt2h,strpos(strmid(qq(2),pt2h,10),'"')) ;--------------------------------------------------------------- ; go through looking for section divisions and names ;--------------------------------------------------------------- add_seg = intarr(4,50) & k=1 name_pos = intarr(2,1000) & name_text = strarr(1000) & kname=0 IsIndex = 0 IsAppendix = 0 for j=0,nl-1 do begin nww = strpos(qq(j),'!www---') if nww gt 0 then begin print,j,qq(j:j+1),format='(i6,3x,2a)' add_seg(0,k)=j & k=k+1 if strpos(qq(j),'!www---INDEX') gt 0 then IsIndex=k-1 if strpos(qq(j),'!www---APPENDIX') gt 0 then begin IsAppendix = k-1 endif endif nNAM = strpos(qq(j),'') cc1 = strmid(contents,0,pc1+5) ;Contents H1 statement contents = '
'+strmid(contents,pc1+5,strlen(contents)+100) contents = str_sep(contents,'
')+'' contents = [qqseg(0),cc1,contents] qqseg = contents & nstat = n_elements(qqseg) contents_qsec = strarr(nstat) end (IsAppendix gt 0) and (jseg eq IsAppendix): begin ;Appendix (was nset+2) section = outname+'_appendix.html' ; append the footnotes to the Appendices print,'>>>>>>Footnotes: ',jfoot if jfoot gt 0 then begin footnotes = qq(add_seg(0,nsect+4)+1:add_seg(1,nsect+4)) qqseg = [qqseg,footnotes] nstat = n_elements(qqseg) qqseg = qqseg(0:nstat-3) ;drop TtH translation statements nstat = n_elements(qqseg) endif end (IsIndex gt 0) and (jseg eq IsIndex): begin ;Index (was nsect+3) section = outname+'_index.html' bgcolor='ivory' qqseg = qqseg(1:*) ;drop 1st line, contents not prepended nstat = n_elements(qqseg) end else: section = outname+'_sec'+strtrim(string(jseg-1,format='(i2)'),2)+'.html' endcase ;--------------------------------------------------------------- ; modify any references found in the section ;--------------------------------------------------------------- ; define the types of TtH reference tth_types = 'tth' + ['_sEc','FtNt','Fref','_fIg','xxxx'] if jseg ge 1 then begin print,'** Re-jig href statements' for jline = 0,nstat-1 do begin jpoint = 0 rescan: cline = qqseg(jline) ; any hypertext link begins with "href" phref = strpos(strmid(cline,jpoint,5000),'href') if phref gt 0 then begin phref = phref + jpoint ; print,jline,qqseg(jline),format='(i6,3x,a)' print,strmid(cline,phref,50) ; if there is a "#", it is a names reference of som type phash = strpos(strmid(cline,phref,50),'#') ;; phash = strpos(cline,'#') if phash gt 0 then begin phash = phash + phref ttype = strmid(cline,phash+1,7) wtype = (where(ttype eq tth_types))(0) case 1 of ;>>> first consider the case of a TtH reference; treat accordingly (wtype eq 0) or (wtype eq 1): begin ;section or footnote qsec = strmid(cline,phash+8,5) pdot = strpos(qsec,'.') if pdot le 0 then pdot = strpos(qsec,'"') qsec = strmid(qsec,0,pdot) print,qsec,' <<** #tth REFERENCE: ',tth_types(wtype),jline,jpoint,phash if (wtype eq 1) then begin ;(footnote) ;; tref = strmid(cline,phash+8,3) ;; if jseg lt nseg-1 then begin ftnt_refs(0,jfoot) = strtrim(string(jseg-1),2) ftnt_refs(1,jfoot) = qsec ;tref jfoot = jfoot+1 ;; endif endif end (wtype eq 2): begin ;back-link from footnote tref = strmid(cline,phash+8,3) qfoot = (where(tref eq ftnt_refs(1,0:jfoot-1)))(0) print,'******',ftnt_refs(0,qfoot),'+++',ftnt_refs(1,qfoot),format='(4a)' print,tref,' <<** #tth REFERENCE: ',tth_types(wtype),jline,jpoint,phash qsec = ftnt_refs(0,qfoot) ;back reference end (wtype eq 3): begin ;figure tref = strmid(cline,phash+8,1) qsec = strtrim(string(jseg-1),2) print,tref,' <<<<** #tth FIGURE: ',tth_types(wtype),jline,jpoint,phash end ;>>> Not a listed type - must be a LaTeX reference (\ref to a \label) else: begin ;LaTeX reference qsec = strmid(cline,phash,100) pchev = strpos(strmid(cline,phash,100),'>')+phash qsec = strmid(cline,pchev+1,100) if jseg lt nsect+2 then pdot = strpos(qsec,'.') $ else pdot = strpos(qsec,'-') if pdot le 0 then pdot = strpos(qsec,'<') qsec = strmid(qsec,0,pdot) print,qsec,' <<** LaTeX',jline,jpoint,phash qhref = strmid(strmid(cline,phash+1,100),0,strpos(strmid(cline,phash+1,100),'"')) wname = (where(qhref eq name_text))(0) print,'<<< qhref: ',qhref,wname if wname ge 0 then begin print,name_text(wname),name_pos(*,wname) qsec = strtrim(string(name_pos(1,wname)),2) endif end endcase ; construct the revised reference including the outfile name nwhref = outname+'_sec'+qsec+'.html' & len_nwhref = strlen(nwhref) qx = where(qsec eq sect_nos) if qx(0) lt 0 then nwhref = outname+'_appendix.html' nwhref = nwhref+strmid(cline,phash,10000) print,nwhref ncline = strmid(cline,0,phash)+nwhref qqseg(jline) = ncline if jseg eq 1 then contents_qsec(jline) = qsec ; allow for multiple references on the same line print,jpoint,phash,len_nwhref,strlen(ncline),' <<<<<<<<<' jpoint = phash + 7 + len_nwhref if jpoint lt strlen(ncline) then goto, rescan ;>>> href without a #; and EXTERNAL link? endif else begin print,'************ EXTERNAL LINK ************' phash = phref+5 ;; qsec = strmid(cline,phash,100) pchev = strpos(strmid(cline,phash,100),'>')+phash ;; qsec = strmid(cline,pchev+1,100) ;; pdot = strpos(qsec,'.') ;; if pdot le 0 then pdot = strpos(qsec,'<') ;; qsec = strmid(qsec,0,pdot) ;; qsec = strtrim(string(jseg-1),2) ;!!!!!!!!!!!!!! kref = ' target="_top"'+strmid(cline,pchev,100) ncline = strmid(cline,0,pchev) + kref qqseg(jline) = ncline print,qsec,' <<<<<<** LaTeX',jline,phash,pchev,pdot ; allow for several references on a line if pchev+strlen(kref) lt strlen(ncline) then goto, rescan endelse newline: ; ??? how to decide on which section if appendices named wrongly!!! endif ; fix a bug???????????????? qqseg(jline) = str_replace(qqseg(jline),'symbol> ~ ~' printf,lunw,'' printf,lunw,'' case 1 of jseg eq 1: begin ; prepend header part to contents printf,lunw,qq(add_seg(0,0):add_seg(1,0)) ; determine segments of contents to be prepended to sections for jj=2,nsect+2 do begin this_section = where(strtrim(string(jj-1),2) eq contents_qsec) ; print,jj,'<<<< this_section' ; print,this_section add_seg(2,jj) = min(this_section) add_seg(3,jj) = max(this_section) endfor add_seg(2,nsect+2) = add_seg(3,nsect+1)+1 add_seg(3,nsect+2) = nstat-1 end (jseg gt 1) and (jseg le nsect+2): begin ; prepend part of contents for this section print,'>> Prepend contents' printf,lunw,contents(add_seg(2,jseg):add_seg(3,jseg)) end else: print,'Do Nothing - Index?' endcase ; write out the modified text printf,lunw,qqseg,format='(a)' ; add trailer info on translation printf,lunw,'


' printf,lunw,'Converted at the YDAC on '+tdate+'
' $ +'(from LaTEX using ' $ +'TTH, version '+t2h_ver $ +', with postprocessing)' printf,lunw,'' printf,lunw,'' printf,lunw,'' free_lun,lunw ans='' read,'** Continue: ',ans endfor end