@@ -236,15 +236,11 @@ function app:print-function(
236236) as element (div ) {
237237 let $comment := $function/xqdoc:comment
238238 let $function-name := $function/xqdoc:name
239- let $arity := count ($function/xqdoc:comment /xqdoc:param)
240- (: If there are params in the signature, but these are not listed in comment/param,
241- do not state that the number of params is 0. :)
242- let $arity :=
243- if ($arity eq 0 and contains ($function/xqdoc:signature, '$' )) then () else ('.' || $arity)
239+ let $arity := xs:integer ($function/xqdoc:arity)
244240 let $function-identifier :=
245241 (: If the name has no prefix, use the name as it is. :)
246242 if (contains ($function-name, ':' )) then (
247- substring-after ($function-name, ":" ) || $arity
243+ substring-after ($function-name, ":" ) || "." || $arity
248244 ) else (
249245 $function-name || $arity
250246 )
@@ -259,9 +255,7 @@ function app:print-function(
259255 let $extDocs := app:get-extended-doc ($function)[1 ]
260256 return
261257 <div class = "function" id = "{$function-identifier} " >
262- <header class = "function-head" >
263- <pre class = "signature" ><code class = "language-xquery" >{ $function/xqdoc:signature/node () }</code></pre>
264- </header>
258+ { app:print-function-header ($function)}
265259 <div class = "function-detail" >
266260 <p class = "description" >{ $parsed }</p>
267261 {
@@ -311,6 +305,46 @@ function app:print-function(
311305 </div>
312306};
313307
308+ declare %private
309+ function app:print-function-header ($function as element (xqdoc:function )) as element (header) {
310+ <header class = "function-head" >
311+ <h4>{$function/xqdoc:name}#{$function/xqdoc:arity}</h4>
312+ <pre class = "signature" ><code class = "language-xquery hljs" data-highlighted = "yes" >
313+ <span class = "{app:html-class-for-function ($function)} " >{$function/xqdoc:name}</span>({
314+ let $ari := xs:integer ($function/xqdoc:arity)
315+ return
316+ for $para at $pos in $function//xqdoc:parameter
317+ let $comma := if ($ari > 1 and $pos < $ari) then ", " else ()
318+ return (
319+ <span class = "hljs-variable" >{$para/xqdoc:name/string ()}</span>,
320+ " " ,
321+ <span class = "hljs-keyword" >as </span>,
322+ " " ,
323+ <span class = "hljs-type" >{$para/xqdoc:type /string ()}</span>,
324+ $para/xqdoc:type /@occurrence/string () || $comma
325+ )
326+ }) <span class = "hljs-keyword" >as </span>  <span class = "hljs-type" >{$function/xqdoc:return /xqdoc:type /string ()}</span>
327+ </code></pre>
328+ </header>
329+ };
330+
331+ declare %private
332+ function app:html-class-for-function ($function as element (xqdoc:function )) as xs:string {
333+ if (app:is-builtin-function ($function)) then
334+ 'hljs-built_in'
335+ else
336+ 'hljs-title'
337+ };
338+
339+ declare %private
340+ function app:is-builtin-function ($function as element (xqdoc:function )) as xs:boolean {
341+ not (contains ($function/xqdoc:name, ':' )) or
342+ starts-with ($function/xqdoc:name, 'fn:' ) or
343+ starts-with ($function/xqdoc:name, 'math:' ) or
344+ starts-with ($function/xqdoc:name, 'map:' ) or
345+ starts-with ($function/xqdoc:name, 'array:' )
346+ };
347+
314348declare %private
315349function app:include-markdown ($path as xs:string) as element (zero-md) {
316350 <zero-md src = "{ $path } " >
@@ -326,10 +360,12 @@ function app:print-parameters($params as element(xqdoc:param)*) as element(table
326360 <table>
327361 {
328362 (: The data generated by xqdm:scan contains too much white space :)
329- $params/normalize-space () !
363+ for $param in $params
364+ let $split := $param => normalize-space () => tokenize (" " )
365+ return
330366 <tr>
331- <td class = "parameter-name" >{replace (., "^([^\s]+)\s.*$" , "$1" )}</td>
332- <td>{replace (., "^[^\s]+\s(.*)$" , "$1 " )}</td>
367+ <td class = "parameter-name" >{head ($split )}</td>
368+ <td>{tail ($split) => string-join ( " " )}</td>
333369 </tr>
334370 }
335371 </table>
0 commit comments