/* "CodeWorker": a scripting language for parsing and generating text. Copyright (C) 1996-1997, 1999-2002 Cédric Lemaire This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA To contact the author: codeworker@free.fr */ function writeHTML(cChar) { writeText(composeHTMLLikeString(cChar)); } function getHTMLAnchor(sLabel) { set sLabel = replaceString("#", "_", sLabel); set sLabel = replaceString("&", "_amp_", sLabel); set sLabel = replaceString(";", "_", sLabel); set sLabel = replaceString(" ", "_", sLabel); set sLabel = replaceString("%", "_percent_", sLabel); set sLabel = replaceString("@", "_at_", sLabel); set sLabel = replaceString("=", "_eq_", sLabel); set sLabel = replaceString("<", "_lt_", sLabel); set sLabel = replaceString(">", "_gt_", sLabel); set sLabel = replaceString("\"", "_dq_", sLabel); set sLabel = replaceString("'", "_sq_", sLabel); return sLabel; } function getSectionNumber() { local sText; foreach i in this.sectionNumbers { if !first(i) sText += '.'; sText += i; } return sText; } function incrementSectionNumber(iSectionLevel) { while $this.sectionNumbers.size() > iSectionLevel + 1$ this.sectionNumbers.removeLastElement(); if $this.sectionNumbers.size() <= iSectionLevel$ { do pushItem this.sectionNumbers = 1; while $this.sectionNumbers.size() <= iSectionLevel$; } else { increment(this.sectionNumbers#back); } return getSectionNumber(); } LaTeX2HTML ::= parsingMode; parsingMode<"description"> ::= blanks #continue ['\\' #continue #!ignore ['%' => {@%@} | #ignore(LaTeX) command] | '$' mathEscape | paragraphJump | #readChar:cChar => writeHTML(cChar);]* #empty; parsingMode<"chapter"> ::= => { @ User's guide and reference manual @ insert this.sTOCFile = getWorkingPath() + "WebSite/manual_" + replaceString(" ", "_", this.sChapterName) + "_TOC.html"; insert this.sDocumentFile = getWorkingPath() + "WebSite/manual_" + replaceString(" ", "_", this.sChapterName) + ".html"; generated_file(this.sTOCFile) { @ @ } generated_file(this.sDocumentFile) { @ @ } } #ignore(LaTeX) [ "\\newcommand" ignoreBraces [blanks '[' [~']']* ']']* ignoreBraces | "\\special" ignoreBraces | ~"\\pdfchapter" | "\\pdfchapter" #continue [ '*' | rawCompoundText:sName [ => if this.sChapterName && this.sChapterName != sName break; #appendedFile(this.sDocumentFile) chapterContent(sName) | !#empty ] ] ]* #continue #empty => { appended_file(this.sTOCFile) { @ @ } appended_file(this.sDocumentFile) { @ @ } if isEmpty(this.listOfIndices) { @ @ } else { @ @ generated_file(getWorkingPath() + "WebSite/manual_" + replaceString(" ", "_", this.sChapterName) + "_INDEX.html") { @ @ foreach i in sorted no_case this.listOfIndices { if i { @ @replaceString(" ", "_", key(i))@
@ } else { @ @key(i)@
@ } foreach j in sorted i.listOfIndices { @     @replaceString(" ", "_", key(j))@
@ } } @ @ } } @ @}; rawCompoundText:value ::= blanks #!ignore '{' [~'}']*:rawCompoundText '}'; compoundText ::= blanks '{' #continue ['\\' #continue #!ignore ['%' => {@%@} | #ignore(LaTeX) command] | '$' mathEscape | paragraphJump | ~'}':cChar => writeHTML(cChar); ]* '}'; mathEscape ::= ['\\' #continue commandMath | paragraphJump | ~'$']* '$'; commandMath ::= "backslash" => writeText("\\"); | "triangle" => writeText("^"); | "hat" => {writeText("^");}; command ::= [ "begin" #continue begin | "makebox" #continue makeBox | "textit" #continue textIt | "textbf" #continue textBf | "samp" #continue samp | "textrm" #continue textRm | "tiny" #continue tiny | "textsc" #continue textSc | "texttt" #continue textTt | "footnote" #continue footNote | "label" #continue label | "pdflabel" #continue label | "index" #continue index | "ref" #continue reference | "email" #continue email ] | #!ignore specialCommand; begin ::= blanks '{' blanks #continue #readIdentifier:sBegin blanks '}' beginContent "\\end" blanks '{' blanks #readIdentifier blanks '}'; beginContent<"description"> ::= beginContent<"itemize">; beginContent<"itemize"> ::= => {@@ writeText(endl()); }; commandItemize(bFirst : node) ::= "item" => { if bFirst set bFirst = false; else { @@ writeText(endl()); } @
  • @ } | !"end" #continue command; beginContent<"alltt"> ::= => {@

    @} [ '\\' !"end" #continue command | '$' mathEscape | ~'\\':cChar => if cChar != "\r" { if cChar == "\n" { @
    @ writeText(endl()); } else if cChar == " " { @ @ } else if cChar == "\t" { @    @ } else { writeHTML(cChar); } } ]* => {@

    @}; beginContent<"verbatim"> ::= => {@

    @} [ ~"\\end":cChar => if cChar != "\r" { if cChar == "\n" { @
    @ writeText(endl()); } else if cChar == " " { @ @ } else if cChar == "\t" { @    @ } else { writeHTML(cChar); } } ]* => {@

    @}; beginContent<"center"> ::= => {@

    @} [ '\\' !"end" #continue command | '$' mathEscape | ~'\\':cChar => if cChar != "\r" { if cChar == "\n" { @
    @ writeText(endl()); } else if cChar == " " { @ @ } else if cChar == "\t" { @    @ } else { writeHTML(cChar); } } ]* => {@

    @}; beginContent<"tableii"> ::= [blanks '{' [~'}']* '}']2 => {@@ writeText(endl());@@ writeText(endl());} [ => newFloatingLocation("TD"); compoundText => { insertText(getFloatingLocation("TD"), "@ } ]* => {writeText(endl());@@ writeText(endl());} [blanks '\\' !"end" #continue commandTableii]* blanks => {@
    "); @

    @ writeText(endl());}; commandTableii ::= => {@@ writeText(endl());} "lineii" [ => newFloatingLocation("TD"); compoundText => { insertText(getFloatingLocation("TD"), ""); @@ writeText(endl()); } ]* => {@@ writeText(endl());}; beginContent<"tableiii"> ::= [blanks '{' [~'}']* '}']2 => {@@ writeText(endl());@@ writeText(endl());} [ => newFloatingLocation("TD"); compoundText => { insertText(getFloatingLocation("TD"), "@ } ]* => {writeText(endl());@@ writeText(endl());} [blanks '\\' !"end" #continue commandTableiii]* blanks => {@
    "); @

    @ writeText(endl());}; commandTableiii ::= => {@@ writeText(endl());} "lineiii" [ => newFloatingLocation("TD"); compoundText => { insertText(getFloatingLocation("TD"), ""); @@ writeText(endl()); } ]* => {@@ writeText(endl());}; makeBox ::= blanks #continue '[' NUMBER:dLength => { local iSize = floor(mult(dLength, 5)); @@repeatString(" ", iSize)@@ } [~']']* ']' [blanks '[' [~']']* ']'] [compoundText]?; textIt ::= => {@@} compoundText => {@@}; textBf ::= => {@@} compoundText => {@@}; textRm ::= compoundText; footNote ::= #continue =>{@ (@} compoundText =>{@)@}; samp ::= => {@@}compoundText => {@@}; tiny ::= => {@@} [ compoundText | ['\\' #continue command | '$' mathEscape | paragraphJump | ~'}':cChar => writeHTML(cChar); ]* ] => {@@}; textSc ::= => {@@} compoundText => {@@}; textTt ::= blanks '{' blanks => {@

    @} [ '\\' #continue #!ignore ['%' => {@%@} | #ignore(LaTeX) command] | '$' mathEscape | ~'}':cChar => if cChar != "\r" { if cChar == "\n" { @
    @ writeText(endl()); } else { writeHTML(cChar); } } ]* '}' => {@

    @}; label ::= => {@@ set sLabel = getHTMLAnchor(sLabel.coreString(1, 1)); if !findElement(sLabel, this.listOfAnchors) { insert this.listOfAnchors[sLabel] = true; @@ } }; index ::= rawCompoundText:sIndex => { local sLabel; set sIndex = replaceString("\\", "", sIndex); set sIndex = replaceString("<", "<", sIndex); set sIndex = replaceString(">", ">", sIndex); local iIndex = findString(sIndex, "!"); if isPositive(iIndex) { local sEntry = leftString(sIndex, iIndex); set sIndex = subString(sIndex, add(iIndex, 1)); insert this.listOfIndices[sEntry].listOfIndices[sIndex] = true; set sLabel = sEntry + "_" + sIndex; } else { insert this.listOfIndices[sIndex] = true; set sLabel = sIndex; } set sLabel = getHTMLAnchor(sLabel); if !findElement(sLabel, this.listOfAnchors) { insert this.listOfAnchors[sLabel] = true; @@ } }; reference ::= => {@@sText@@}; email ::= '{' #ignore(blanks) "\\WebSite\\" '}' => { @codeworker@ writeText("@"); @free.fr@} | => {@@sText@@} ; chapterContent(sName : value) ::= => { writeText(endl()); local sLabel = getHTMLAnchor(sName); if !findElement(sLabel, this.listOfAnchors) { insert this.listOfAnchors[sLabel] = true; @@ } @

    @sName@

    @ writeText(endl()); appended_file(this.sTOCFile) { set sName = replaceString("-", "_", sName); @
    @replaceString(" ", "_", sName)@
    @ writeText(endl()); } } [!["\\pdfchapter" | "\\printindex" | "\\end"] ['\\' #continue #!ignore ['%' => {@%@} | #ignore(LaTeX) chapterCommand] | '$' mathEscape | paragraphJump | ~'\\':cChar => writeHTML(cChar);]]*; chapterCommand ::= "pdfsection" #continue #ignore(LaTeX) section | command; paragraphJump ::= [['\r']? '\n']2..* => {writeText(endl()); @

    @ writeText(endl());}; section ::= => local sName; [#generatedString(sName) compoundText] => { writeText(endl()); local sLabel = getHTMLAnchor(sName); if !findElement(sLabel, this.listOfAnchors) { insert this.listOfAnchors[sLabel] = true; @@ } @

    @incrementSectionNumber(0)@ @sName@

    @ writeText(endl()); appended_file(this.sTOCFile) { set sName = replaceString("–", "_", sName); @     @getSectionNumber()@_@replaceString(" ", "_", sName)@
    @ writeText(endl()); } } #continue [!["\\pdfchapter"| "\\pdfsection" | "\\printindex" | "\\end"] ['\\' #continue #!ignore ['%' => {@%@} | #ignore(LaTeX) sectionCommand] | '$' mathEscape | paragraphJump | ~'\\':cChar => writeHTML(cChar);]]*; sectionCommand ::= ["pdfsubsection" | "subsection"] #continue subsection | command; subsection ::= => local sName; [#generatedString(sName) compoundText] => { writeText(endl()); local sLabel = getHTMLAnchor(sName); if !findElement(sLabel, this.listOfAnchors) { insert this.listOfAnchors[sLabel] = true; @@ } @

    @incrementSectionNumber(1)@ @sName@

    @ writeText(endl()); appended_file(this.sTOCFile) { set sName = replaceString("–", "_", sName); @         
    @getSectionNumber()@_@replaceString(" ", "_", sName)@
    @ writeText(endl()); } } #continue [!["\\pdfchapter"| "\\pdfsection" | "\\pdfsubsection" | "\\subsection" | "\\printindex" | "\\end"] ['\\' #continue #!ignore ['%' => {@%@} | #ignore(LaTeX) subsectionCommand] | '$' mathEscape | paragraphJump | ~'\\':cChar => writeHTML(cChar);]]*; subsectionCommand ::= ["pdfsubsubsection" | "subsubsection"] #continue subsubsection | command; subsubsection ::= => local sName; [#generatedString(sName) compoundText] => { writeText(endl()); local sLabel = getHTMLAnchor(sName); if !findElement(sLabel, this.listOfAnchors) { insert this.listOfAnchors[sLabel] = true; @@ } @

    @incrementSectionNumber(2)@ @sName@

    @ writeText(endl()); appended_file(this.sTOCFile) { set sName = replaceString("–", "_", sName); @             
    @getSectionNumber()@_@replaceString(" ", "_", sName)@
    @ writeText(endl()); } } #continue [!["\\pdfchapter"| "\\pdfsection" | "\\pdfsubsection" | "\\subsection" | "\\pdfsubsubsection" | "\\subsubsection" | "\\printindex" | "\\end"] ['\\' #continue command | '$' mathEscape | paragraphJump | ~'\\':cChar => writeHTML(cChar);]]*; specialCommand ::= "CodeWorker\\" => {@CodeWorker@} | "SWORD\\" => {@SWORD@} | "GraphViz\\" => {@GraphViz@} | "ACE\\" => {@ACE@} | "libCURL\\" => {@libcurl@} | "JEdit\\" => {@JEdit@} | "TLcleaveland\\" => {@TL@} | "TODO\\" => {@@} | "arobas" => {writeText("@");} | "WebSite\\" => {writeText("codeworker@free.fr");} | '{' => {@{@} | '}' => {@}@} | '@' => {writeText("@");} | '#' => {@#@} | '_' => {@_@} | '&' => {@&@} | '%' => {@%@} | '^' => {@^@} | '~' ['{' '}']? => {@~@} | "'e" => {@é@} | '\\' [' '| '\t' | '\r']* ['\n']? => {@
    @ writeText(endl());} | '\"' => {@"@} | '$' => {@$@}; ignoreBraces ::= blanks '{' [ignoreBraces | ~'}']* '}'; blanks ::= [' '| '\t' | '\r' | '\n']*; DIGIT ::= '0'..'9'; NUMBER ::= #!ignore [DIGIT]+ ['.' [DIGIT]+]? [['e' | 'E'] ['+' | '-']? [DIGIT]+]?;