updated stylesheets

highlight PHP automatically
This commit is contained in:
nlopess
2004-03-24 15:54:31 +00:00
parent 7f767e645b
commit e2f9d174b2
5 changed files with 600 additions and 350 deletions

View File

@@ -46,6 +46,7 @@ web: FORCE
@test -d phpweb || mkdir phpweb
$(JADE) $(CATALOG) -d $(PHPWEB_STYLESHEET) -V use-output-dir -t sgml $(XMLDCL) manual.xml
$(PHP) scripts/generate_web.php
$(PHP) scripts/html_syntax.php php phpweb/
test:
$(NSGMLS) -i lang-$(LANG) -s $(XMLDCL) manual.xml

View File

@@ -9,6 +9,7 @@
;; Stylesheets Localization
(define %default-language% "en")
(define %root-filename% "index")
(define %use-id-as-filename% #t)
(define %gentext-nav-tblwidth% "100%")
(define %refentry-function% #t)
@@ -23,24 +24,335 @@
(define %number-programlisting-lines% #f)
(define %linenumber-mod% 1)
(define %shade-verbatim% #t)
(define ($generate-book-lot-list$)
;; REFENTRY generate-book-lot-list
;; PURP Which Lists of Titles should be produced for Books?
;; DESC
;; This parameter should be a list (possibly empty) of the elements
;; for which Lists of Titles should be produced for each 'Book'.
;;
;; It is meaningless to put elements that do not have titles in this
;; list. If elements with optional titles are placed in this list, only
;; the instances of those elements that do have titles will appear in
;; the LOT.
;;
;; /DESC
;; AUTHOR N/A
;; /REFENTRY
(list (normalize "table")))
(define %prefers-ordinal-label-name-format% #f)
(define ($generate-book-lot-list$) (list))
(define (php-code code)
(make processing-instruction
data: (string-append "php " code "?")))
(define quicksort
(quicksort::generic null? car cdr append cons '()))
(define nl-quicksort
(quicksort::generic node-list-empty?
node-list-first
node-list-rest
node-list
node-list
(empty-node-list)))
(define quicksort::generic
(lambda(is-null? first others concat add empty)
(letrec ((collect
;; Collect is an helper function doing the real work
(lambda (pivot ls lgroup rgroup less?)
(if (is-null? ls)
(concat (impl lgroup less?)
(add pivot (impl rgroup less?)))
(if (less? pivot (first ls))
(collect pivot (others ls) lgroup
(add (first ls) rgroup)
less?)
(collect pivot (others ls)
(add (first ls) lgroup)
rgroup
less?)))))
(impl
;; impl first test some trivial sorting case and then call
;; the procedure collect
(lambda (ls less?)
(if (or (is-null? ls) (is-null? (others ls)))
ls
(collect (first ls) (others ls) empty empty less?)))))
;; we return the new defined procedure
impl)))
;; Polish definitions
(define (gentext-pl-nav-next next)
(make sequence (literal "Nast\U-0119;pny")))
(define (book-titlepage-recto-elements)
(list (normalize "title")
(normalize "subtitle")
(normalize "graphic")
(normalize "mediaobject")
(normalize "corpauthor")
(normalize "authorgroup")
(normalize "author")
(normalize "editor")
(normalize "pubdate")
(normalize "copyright")
(normalize "abstract")
(normalize "legalnotice")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
;;;; render function prototypes, esp. with optional arguments
;;;; for new docbook4 methodsynopsis tag and friends
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; helper function generating closing optional brackets
(define (methodsynopsis-generate-closing-optionals nl)
(if (node-list-empty? nl)
(empty-sosofo) ;; empty list -> do nothing
(make sequence ;; process list node
(if (or (and (attribute-string (normalize "choice") (node-list-first nl))
(string=? "opt" (attribute-string (normalize "choice") (node-list-first nl)))
)
(has-default-value (node-list-first nl)))
(literal %arg-choice-opt-close-str%) ;; is optional parameter -> close a bracket
(empty-sosofo)
)
(methodsynopsis-generate-closing-optionals (node-list-rest nl)) ;; process rest of list
)
)
)
(define (is-true-optional nl)
(and (equal? (gi (parent nl)) (normalize "parameter"))
(equal? 0 (string-length (strip (data (preced nl)))))
(equal? 0 (string-length (strip (data (follow nl)))))
)
)
(define (has-true-optional nl)
(is-true-optional
(node-list-first-element
(select-elements
(descendants nl)
(normalize "optional"))
)
)
)
(define (count-true-optionals nl)
(let loop
((result 0)
(nl (select-elements (descendants nl) (normalize "optional")))
)
(if(node-list-empty? nl)
result
(if(is-true-optional(node-list-first nl))
(loop (+ result 1) (node-list-rest nl))
(loop result (node-list-rest nl))
)
)
)
)
(define (has-default-value nl)
(not (node-list-empty? ( select-elements (descendants nl) (normalize "initializer"))))
)
;; render classsynopsis
(element classsynopsis
(make sequence
(literal "class ")
(process-children-trim)
(literal "}")
)
)
(element ooclass (make sequence (process-children)))
(element (ooclass classname)
(make sequence
($bold-seq$
(process-children-trim)
)
(literal " { ")
(linebreak)
)
)
;; render methodsynopsis
(element methodsynopsis
(make sequence
(process-children) ;; render content
(methodsynopsis-generate-closing-optionals (children (current-node))) ;; close optional brackets
(literal ")") ;; close parameter list
(linebreak)
)
)
(element constructorsynopsis
(make sequence
(process-children) ;; render content
(methodsynopsis-generate-closing-optionals (children (current-node))) ;; close optional brackets
(literal ")") ;; close parameter list
(linebreak)
)
)
;; render return type
(element (methodsynopsis type)
(make sequence
(process-children-trim)
(literal " ")
)
)
;; render function name
(element (methodsynopsis methodname)
(make sequence
($bold-seq$
(process-children-trim)
)
(literal " ( ") ;; start parameter list
)
)
(element (constructorsynopsis methodname)
(make sequence
($bold-seq$
(process-children-trim)
)
(literal " ( ") ;; start parameter list
)
)
;; render parameters
(element (methodsynopsis methodparam)
(make sequence
;; special case -> first parameter is optional
(if (equal? (gi (ipreced (current-node))) (normalize "methodparam"))
(empty-sosofo) ;; have prev. parameters -> is not first
(if (or (equal? (attribute-string (normalize "choice")) "opt")
(has-default-value (current-node))
)
(literal %arg-choice-opt-open-str%) ;; generate opening bracket
(empty-sosofo)
)
)
(process-children-trim)
;; have more parameters following me?
(if (equal? (gi (ifollow (current-node))) (normalize "methodparam"))
(make sequence
;; is next parameter optional?
(if (or (equal? (attribute-string (normalize "choice") (ifollow (current-node))) "opt")
(has-default-value (ifollow (current-node)))
)
(make sequence
(literal " ")
(literal %arg-choice-opt-open-str%)
)
(empty-sosofo)
)
;; parameter list separator
(literal ", ")
)
(empty-sosofo)
)
)
)
;; render parameters
(element (constructorsynopsis methodparam)
(make sequence
;; special case -> first parameter is optional
(if (equal? (gi (ipreced (current-node))) (normalize "methodparam"))
(empty-sosofo) ;; have prev. parameters -> is not first
(if (or (equal? (attribute-string (normalize "choice")) "opt")
(has-default-value (current-node))
)
(literal %arg-choice-opt-open-str%) ;; generate opening bracket
(empty-sosofo)
)
)
(process-children-trim)
;; have more parameters following me?
(if (equal? (gi (ifollow (current-node))) (normalize "methodparam"))
(make sequence
;; is next parameter optional?
(if (or (equal? (attribute-string (normalize "choice") (ifollow (current-node))) "opt")
(has-default-value (ifollow (current-node)))
)
(make sequence
(literal " ")
(literal %arg-choice-opt-open-str%)
)
(empty-sosofo)
)
;; parameter list separator
(literal ", ")
)
(empty-sosofo)
)
)
)
;; special "void" return type tag
(element (methodsynopsis void)
(literal "void ")
)
;; render parameter type
(element (methodparam type)
(make sequence
(process-children-trim)
(literal " ")
)
)
;; render parameter name
(element (methodparam parameter)
(make sequence
(process-children-trim)
)
)
;; render default value
(element (methodparam initializer)
(make sequence
(literal "=")
($italic-seq$ (process-children-trim))
)
)
;; render fieldsynopsis
(element fieldsynopsis
(make sequence
(process-children)
(linebreak)
)
)
(element (fieldsynopsis type)
(make sequence
(process-children-trim)
(literal " ")
)
)
(element (fieldsynopsis varname)
(make sequence
(process-children-trim)
)
)
;; render SGML tags
(element sgmltag
(make sequence
($bold-seq$ (literal "<"))
($bold-seq$ (process-children))
($bold-seq$ (literal ">"))
)
)

View File

@@ -3,19 +3,25 @@
;; $Id$
;;
;; Returns the depth of the auto-generated TOC (table of contents) that
;; should be made at the nd-level
;; Returns the depth of the auto-generated TOC (table of
;; contents) that should be made at the nd-level
(define (toc-depth nd)
(if (string=? (gi nd) (normalize "book"))
3 ; the depth of the top-level TOC
(if (string=? (gi nd) "book")
2 ; the depth of the top-level TOC
1 ; the depth of all other TOCs
))
;; re-defining element-id as we need to get the id of the parent
;; element not only for title but also for question in the faq
(define (element-id #!optional (nd (current-node)))
(let ((elem (if (equal? (gi nd) (normalize "title")) (parent nd)
(if (equal? (gi nd) (normalize "question")) (parent nd)
nd))))
(if (attribute-string (normalize "id") elem)
(attribute-string (normalize "id") elem)
(generate-anchor elem))))
;; Make function definitions bold
(element (funcdef function)
($bold-seq$
(make sequence
@@ -25,44 +31,9 @@
)
(define (is-true-optional nl)
(and (equal? (gi (parent nl)) (normalize "parameter"))
(equal? 0 (string-length (strip (data (preced nl)))))
(equal? 0 (string-length (strip (data (follow nl)))))
)
)
(define (has-true-optional nl)
(is-true-optional
(node-list-first-element
(select-elements
(descendants nl)
(normalize "optional"))
)
)
)
(define (count-true-optionals nl)
(let loop
((result 0)
(nl (select-elements (descendants nl) (normalize "optional")))
)
(if(node-list-empty? nl)
result
(if(is-true-optional(node-list-first nl))
(loop (+ result 1) (node-list-rest nl))
(loop result (node-list-rest nl))
)
)
)
)
;; there are two different kinds of optionals
;; optional parameters and optional parameter parts
;; an optional parameter is identified by an optional tag
;; There are two different kinds of optionals
;; optional parameters and optional parameter parts.
;; An optional parameter is identified by an optional tag
;; with a parameter tag as its parent
;; and only whitespace between them
(element optional
@@ -79,7 +50,15 @@
)
)
;; now this is going to be tricky
;; Print out parameters in italic
(element (paramdef parameter)
(make sequence
font-posture: 'italic
(process-children-trim)
)
)
;; Now this is going to be tricky
(element paramdef
(make sequence
;; special treatment for first parameter in funcsynopsis
@@ -133,15 +112,14 @@
)
)
(element function
(let* ((function-name (data (current-node)))
(linkend
(string-append
"function."
(string-replace
(case-fold-down (string-replace
(string-replace function-name "_" "-")
"::" ".")))
"::" "."))))
(target (element-with-id linkend))
(parent-gi (gi (parent))))
(cond
@@ -149,7 +127,7 @@
((equal? parent-gi "funcdef")
(process-children))
;; if a valid ID for the target function is not found, or if the
;; If a valid ID for the target function is not found, or if the
;; FUNCTION tag is within the definition of the same function,
;; make it bold, add (), but don't make a link
((or (node-list-empty? target)
@@ -163,13 +141,13 @@
(ancestor-member (parent) (list "refentry")))
"refnamediv")))
"refname"))))
function-name))
(case-fold-down function-name)))
($bold-seq$
(make sequence
(process-children)
(literal "()"))))
;; else make a link to the function and add ()
;; Else make a link to the function and add ()
(else
(make element gi: "A"
attributes: (list
@@ -181,134 +159,8 @@
)
(literal "()"))))))))
(element command
(let* ((command-name (data (current-node)))
(linkend
(string-append
"language.function."
(string-replace
(string-replace command-name "_" ".")
"::" ".")))
(target (element-with-id linkend))
(parent-gi (gi (parent))))
(cond
;; function names should be plain in FUNCDEF
((equal? parent-gi "funcdef")
(process-children))
;; if a valid ID for the target function is not found, or if the
;; FUNCTION tag is within the definition of the same function,
;; make it bold, add (), but don't make a link
((or (node-list-empty? target)
(equal? (case-fold-down
(data (node-list-first
(select-elements
(node-list-first
(children
(select-elements
(children
(ancestor-member (parent) (list "refentry")))
"refnamediv")))
"refname"))))
command-name))
($bold-seq$
(make sequence
(literal "{")
(process-children)
(literal "}"))))
;; else make a link to the function and add ()
(else
(make element gi: "A"
attributes: (list
(list "HREF" (href-to target)))
($bold-seq$
(make sequence
(literal "{")
(process-children)
(literal "}"))))))))
(element classname
(let* ((class-name (data (current-node)))
(linkend
(string-append
"class."
(string-replace
(case-fold-down class-name) "_" "-")))
(target (element-with-id linkend))
(parent-gi (gi (parent))))
(cond
;; function names should be plain in SYNOPSIS
((equal? parent-gi "synopsis")
(process-children))
;; if a valid ID for the target class is not found, or if the
;; CLASSNAME tag is within the definition of the same class,
;; make it bold, but don't make a link
((or (node-list-empty? target)
(equal? (case-fold-down
(data (node-list-first
(select-elements
(node-list-first
(children
(select-elements
(children
(ancestor-member (parent) (list "refentry")))
"refnamediv")))
"refname"))))
class-name))
($bold-seq$
(process-children)))
;; else make a link to the function and add ()
(else
(make element gi: "A"
attributes: (list
(list "HREF" (href-to target)))
($bold-seq$
(process-children)))))))
(element constant
(let* ((constant-name (data (current-node)))
(linkend
(string-append "constant."
(case-fold-down
(string-replace constant-name "_" "-"))))
(target (element-with-id linkend))
(parent-gi (gi (parent))))
(cond
; ;; constant names should be plain in FUNCDEF
; ((equal? parent-gi "funcdef")
; (process-children))
;; if a valid ID for the target constant is not found, or if the
;; CONSTANT tag is within the definition of the same constant,
;; make it bold, add (), but don't make a link
((or (node-list-empty? target)
(equal? (case-fold-down
(data (node-list-first
(select-elements
(node-list-first
(children
(select-elements
(children
(ancestor-member (parent) (list "refentry")))
"refnamediv")))
"refname"))))
constant-name))
($bold-mono-seq$
(process-children)))
;; else make a link to the function and add ()
(else
(make element gi: "A"
attributes: (list
(list "HREF" (href-to target)))
($bold-mono-seq$
(process-children)))))))
;; Dispaly of examples
(element example
(make sequence
(make element gi: "TABLE"
@@ -323,13 +175,7 @@
($formal-object$))))))
(element (paramdef parameter)
(make sequence
font-posture: 'italic
(process-children-trim)
)
)
;; Prosessing tasks for the frontpage
(mode book-titlepage-recto-mode
(element authorgroup
(process-children))
@@ -343,40 +189,63 @@
attributes: (list (list "CLASS" (gi)))
(literal author-name))
(process-node-list author-affil))))
)
(define (chunk-element-list)
(list (normalize "preface")
(normalize "chapter")
(normalize "appendix")
(normalize "article")
(normalize "glossary")
(normalize "bibliography")
(normalize "index")
(normalize "colophon")
(normalize "setindex")
(normalize "reference")
(normalize "refentry")
(normalize "part")
(normalize "sect1")
(normalize "sect2")
(normalize "section")
(normalize "book") ;; just in case nothing else matches...
(normalize "set") ;; sets are definitely chunks...
))
(define ($section-body$)
(element editor
(let ((editor-name (author-string)))
(make sequence
(if (first-sibling?)
(make element gi: "H2"
attributes: (list (list "CLASS" "EDITEDBY"))
(literal (gentext-edited-by)))
(empty-sosofo))
(make element gi: "DIV"
attributes: (list (list "CLASS" (gi)))
($section-separator$)
($section-title$)
(literal editor-name)))))
)
(if (or (not (node-list-empty? (select-elements (children (current-node))
(normalize "sect2"))))
(not (node-list-empty? (select-elements (children (current-node))
(normalize "sect3")))))
(build-toc (current-node) 1)
;; Display of question tags, link targets
(element question
(let* ((chlist (children (current-node)))
(firstch (node-list-first chlist))
(restch (node-list-rest chlist)))
(make element gi: "B"
(make element gi: "DIV"
attributes: (list (list "CLASS" (gi)))
(make element gi: "P"
(make element gi: "A"
attributes: (list (list "NAME" (element-id)))
(empty-sosofo))
(make element gi: "B"
(literal (question-answer-label (current-node)) " "))
(process-node-list (children firstch)))
(process-node-list restch)))) )
(process-children)))
;; Adding class HTML parameter to examples
;; having a role parameter, to make PHP examples
;; distinguisable from other ones in the manual
(define ($verbatim-display$ indent line-numbers?)
(let (
(content (make element gi: "PRE"
attributes: (list
(list "CLASS" (if (attribute-string (normalize "role"))
(attribute-string (normalize "role"))
(gi))))
(if (or indent line-numbers?)
($verbatim-line-by-line$ indent line-numbers?)
(process-children-trim)))))
(if %shade-verbatim%
(make element gi: "TABLE"
attributes: (list
(list "BORDER" "0")
(list "BGCOLOR" "#E0E0E0")
(list "CELLPADDING" "5")
)
(make element gi: "TR"
(make element gi: "TD"
content)))
(make sequence
(para-check)
content
(para-check 'restart)))))
(define (linebreak) (make element gi: "BR" (empty-sosofo)))

View File

@@ -12,10 +12,7 @@
</authorgroup>
<pubdate>&build-date;</pubdate>
<copyright>
<year>2001</year>
<year>2002</year>
<year>2003</year>
<year>2004</year>
<year>2001-2004</year>
<holder>ispi of Lincoln, Inc.</holder>
</copyright>
</bookinfo>

71
docs/scripts/html_syntax.php Executable file
View File

@@ -0,0 +1,71 @@
<?php
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2004 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Jakub Vr<56>na <vrana@php.net> |
| Nuno Lopes <nlopess@php.net> |
+----------------------------------------------------------------------+
| Highlight PHP examples |
+----------------------------------------------------------------------+
$Id$
*/
if ($_SERVER["argc"] < 3) {
exit("Purpose: Syntax highlight PHP examples in DSSSL generated HTML manual.\n"
.'Usage: html_syntax.php [ "html" | "php" ] [ filename.ext | dir | wildcard ] ...' ."\n"
.'"html" - highlight_string() is applied, "php" - highlight_php() is added' ."\n"
);
}
set_time_limit(5*60); // can run long, but not more than 5 minutes
function callback_html_number_entities_decode($matches) {
return chr($matches[1]);
}
function callback_highlight_php($matches) {
$with_tags = preg_replace_callback("!&#([0-9]+);!", "callback_html_number_entities_decode", $matches[1]);
if ($GLOBALS["TYPE"] == "php") {
return "\n<?php\nhighlight_php('". addcslashes($with_tags, "'\\") ."');\n?>\n";
} else { // "html"
return highlight_string($with_tags, true);
}
}
$files = $_SERVER["argv"];
array_shift($files); // $argv[0] - script filename
$TYPE = array_shift($files); // "html" or "php"
while (($file = array_shift($files)) !== null) {
if (is_file($file)) {
$process = array($file);
} elseif (is_dir($file)) {
$lastchar = substr($file, -1);
$process = glob($file . ($lastchar == "/" || $lastchar == "\\" ? "*" : "/*"));
} else { // should be wildcard
$process = glob($file);
}
foreach ($process as $filename) {
if (!is_file($filename)) { // do not recurse
continue;
}
$original = file_get_contents($filename);
$highlighted = preg_replace_callback("!<PRE\r?\nCLASS=\"php\"\r?\n>(.*)</PRE\r?\n>!sU", "callback_highlight_php", $original);
if ($original != $highlighted) {
$fp = fopen($filename, "w");
fwrite($fp, $highlighted);
fclose($fp);
}
}
}
?>