Index: openacs-4/packages/acs-tcl/tcl/text-html-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/text-html-procs.tcl,v diff -u -r1.112 -r1.113 --- openacs-4/packages/acs-tcl/tcl/text-html-procs.tcl 8 Oct 2024 14:13:37 -0000 1.112 +++ openacs-4/packages/acs-tcl/tcl/text-html-procs.tcl 27 Oct 2024 16:51:11 -0000 1.113 @@ -2525,7 +2525,7 @@ } { Returns true of ad_html_text_convert can handle the given from and to mime types. } { - set valid_froms { text/enhanced text/markdown text/plain text/fixed-width text/html text/xml } + set valid_froms { text/enhanced text/markdown text/plain text/fixed-width text/html text/xml application/docbook+xml } set valid_tos { text/plain text/html } # Validate procedure input switch $from { @@ -2767,6 +2767,17 @@ } } } + application/docbook+xml { + switch -- $to { + text/html { + set text [ad_docbook_xml_to_html $text] + } + text/plain { + set text [ad_docbook_xml_to_html $text] + set text [ad_html_to_text -maxlen $maxlen -- $text] + } + } + } } # Handle closing of HTML tags, truncation @@ -2787,6 +2798,152 @@ return $text } +ad_proc -private ad_docbook_xml_to_html { + text +} { + + Converts DocBook XML as used in the OpenACS documentation to HTML. + This is not a full implementation of all possible DocBook markup, + but just a subset sufficient for rendering a substantial subset of + the OpenACS documentation. + + @param text input text + @author Gustaf Neumann + @creation-date 2024-10-27 +} { + # + # Strip XML declaration and doctype without looking into its + # content. + # + regexp {^<[?]xml\s+version='1.0'\s+[?]>\n(.*)$} $text . text + regexp {^\n(.*)$} $text . text + + set parsedList [ns_parsehtml $text] + set tagstack {} + + # + # "::__doc_parsed_text" is used just for development/debugging + # purposes. + # + set ::__doc_parsed_text $parsedList + + set silentlyIgnoredTags { + authorblurb /authorblurb + /ulink + } + set parsedPage "" + foreach parseListElement $parsedList { + #append parsedPage START $parseListElement END \n + lassign $parseListElement kind chunk parsed + if {$kind eq "tag"} { + set tag [string tolower [lindex $parsed 0]] + set dict [lindex $parsed 1] + switch $tag { + sect1 { + dict set ::properties section 2 + append parsedPage [subst {
} + /para { append parsedPage
} + + emphasis { append parsedPage {}} + /emphasis { append parsedPage } + + term { append parsedPage [subst {}] } + /term { append parsedPage } + + replaceable { append parsedPage [subst {}] } + /replaceable { append parsedPage } + + phrase { append parsedPage [subst {}] } + /programlisting { append parsedPage\n} + + computeroutput { append parsedPage [subst {}] } + /computeroutput { append parsedPage {} } + + itemizedlist { append parsedPage [subst {