function str2html, text, _extra=_extra, headers=headers, nolinks=nolinks, $
    link_text=link_text
;
if not keyword_set(link_text) then link_text="More Information"
remtab,text,ttext               ; tabs -> spaces
if n_elements(ttext) eq 1 then ttext=['',ttext]
ttext=strlist2html(ttext,/all)          ; convert ordered lists

; ----------- find URLS and substitute active links -------------
term=['html',' ']


titss=where_title(ttext,title=titles)

if titss(0) ne -1 then begin
   ttext(titss)='<hr>'
   sst=where(titles ne '',sstcnt)
   if sstcnt gt 0 then ttext(titss(sst))=ttext(titss(sst)) + $
      '<h4>' + titles(sst) + '</h4>'
endif

if not keyword_set(nolinks) then begin
   chk=wc_where(ttext,'*http:*',mcount,/case_ignore)
   if mcount gt 1 and n_elements(link_text) eq 1 then $
      link_text=replicate(link_text,mcount)
   for i=0,mcount-1 do begin
      url=strpos(strlowcase(ttext(chk(i))),'http:') ;
      if url(0) ne -1 then begin
         urlfull=''
         for trm=0,n_elements(term)-1 do begin
            last=strpos(strlowcase(strmid(ttext(chk(i)),url(0),120)),term(trm))
            if last(0) ne -1 then urlfull=strmid(ttext(chk(i)),url(0), $
               last + strlen(term(trm)))
         endfor         
         if urlfull eq '' then urlfull=strmid(ttext(chk(i)),url(0),120)
      endif

      urlfull=strcompress(urlfull,/remove)
;     eliminate bad termination characters...
      if strmid(urlfull,strlen(urlfull)-1,1) eq '.' then $
         urlfull=strmid(urlfull,0,strlen(urlfull)-1)
      urlfull=strcompress(urlfull,/remove)
      new=str_replace(ttext(chk(i)),urlfull, $
          '<a HREF="' + urlfull + '"><B>' + link_text(i) + '</B></a>')
      ttext(chk(i))=new
   endfor
endif
; -------------------------------------------------------------------


; bracket tables with <p><pre>TABLE</pre>
tables=where_table(ttext,tcnt,_extra=_extra)    ; find tables

if tcnt gt 0 then begin
   ttext(tables(*,0))='<p><pre>' + ttext(tables(*,0))
   ttext(tables(*,1))=ttext(tables(*,1)) + '</pre>'
endif

nulls=where(ttext eq '',ncnt)
nnulls=where(ttext ne '',nncnt)     ; not nulls

if ncnt gt 0 then ttext(nulls)='<p>'

if keyword_set(headers) then begin
   hlev=strtrim(headers < 5,2)
   headers=where(deriv_arr(nulls) eq 2,hcnt)
   hss=nulls(headers)+1 < (n_elements(ttext)-1) 
   if hcnt gt 0 then ttext(hss) = $
      '<h'+hlev+'>' + ttext(hss) + '</h' + hlev + '>'
endif


; eliminate duplicate records (['<p>','<p>','<hr>','<hr']

ttext=ttext(uniq(ttext))    ; dont sort it...

; upgrade First line titles headers

ss=where(ttext eq '<hr>' and shift(ttext,-1) eq '<p>' and $
   shift(ttext,-2) ne '<p>' and shift(ttext,-3) eq '<p>',tcnt)

if tcnt gt 0 then ttext(ss+2)='<h5>' + ttext(ss+2) + '</h5>'

return,ttext
end