#!/usr/bin/env newlisp
#
# this utility may be call from Makefile in the main source distribution directory:
#     make preparepdf
#
# This is necessary when using OpenOffice HTML->PDF conversion
#
# to prepare the file for PDF conversion, byt replaceing all <span class="function"></span>
# with <font color="#DD0000"></font> in the syntax statements and replacing &rarr; (one line
# arrow with &rArr; (double line arrow)
#
# USAGE: preparepdf newlisp_manual.html newlisp_manual_preparepdf.html
#
(set 'text (read-file (main-args 2))) ; input file

(println "taking out xml tag and DOCTYPE tag")
(replace {<\?xml[^>]*>} text "" 0)
(replace {<\!DOCTYPE[^>]*>} text "" 0)

(replace {(<h2><span class="function">)(.*?)</span>(.*?)</h2>} text 
         (append {<h2><font color="#DD0000">} $2 {</font>} $3 {</h2>}) 0)

(println $0 " replacements made for syntax color")

(replace {&rarr;} text {&rArr;} 0)

(println $0 " replacements made for arrow code")

(write-file (main-args 3) text) ; output file

(exit)


