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 {
}] \n + } + sect2 { + dict set ::properties section 3 + append parsedPage [subst {
}] \n + } + sect3 { + dict set ::properties section 4 + append parsedPage [subst {
}] \n + } + /sect1 - + /sect2 - + /sect3 { + append parsedPage
\n + } + title { append parsedPage } + /title { append parsedPage } + + ulink {dict set ::properties ulink $parsed} + + para { append parsedPage

} + /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 {
}] } + /phrase { append parsedPage
} + + programlisting { append parsedPage [subst {
}] }
+                /programlisting { append parsedPage 
\n} + + computeroutput { append parsedPage [subst {}] } + /computeroutput { append parsedPage {} } + + itemizedlist { append parsedPage [subst {
    }]} + /itemizedlist { append parsedPage
\n} + + orderedlist { append parsedPage [subst {
    }]} + /orderedlist { append parsedPage
} + + listitem { + set item [expr {[lindex $tagstack end] eq "varlistentry" ? "dd" : "li" }] + #ns_log notice "listitem sees '[lindex $tagstack end]' -- $tagstack" + append parsedPage [subst {<$item class="$tag">}] + } + /listitem { + set item [expr {[lindex $tagstack end] eq "varlistentry" ? "dd" : "li" }] + append parsedPage + } + + variablelist { append parsedPage [subst {
}] } + /variablelist { append parsedPage
\n} + + varlistentry { append parsedPage [subst {
}] } + /varlistentry { append parsedPage
\n} + + anchor { append parsedPage [subst { }] } + xref { + # + # We should actually get the page name of the + # target page + # + set target [dict get $dict linkend] + set name $target + append parsedPage [subst {$name }] + } + + default { + #append parsedPage "ignore '$tag'\n" + if {$tag ni $silentlyIgnoredTags} { + append parsedPage "ignore '$parseListElement'\n" + ns_log notice "ignore '$parseListElement'" + } + } + } + if {[string range $tag 0 0] eq "/"} { + #ns_log notice "old tagstack <$tagstack> (closing $tag)" + set tagstack [lreplace $tagstack end end] + #ns_log notice "new tagstack <$tagstack>" + } elseif {$tag ni {anchor xref} } { + lappend tagstack $tag + } + } elseif {$kind eq "text"} { + set context [lindex $tagstack end] + #append parsedPage CONTEXT=$context: + if {$context eq "ulink"} { + append parsedPage [subst {$chunk}] + } else { + append parsedPage $chunk + } + } + } + return $parsedPage +} + + ad_proc -public ad_enhanced_text_to_html { text } {