Coder Social home page Coder Social logo

phd's Introduction

PhD - PHP DocBook

About PhD

PhD is PHP's DocBook rendering system which is used to convert the PHP Manual into different output formats.

Requirements

  • PHP 8.0+
  • DOM, libXML2, XMLReader and SQLite3.

Rendering the PHP Documentation Sources

To render the PHP documentation, you will need to clone the documentation source files, doc-base and PhD.

To get the PHP documentation sources, clone them from the official GitHub repositories. To clone the English documentation:

$ git clone https://github.com/php/doc-en en
List of languages/repositories

To check the documentation and combine it into one file, you need to clone PHP's doc-base repository

$ git clone https://github.com/php/doc-base

and run configure.php

$ php doc-base/configure.php

which will generate a .manual.xml file in the doc-base directory.

To render the documentation in xhtml format into the default ./output/ directory:

$ php phd/render.php -d doc-base/.manual.xml -P PHP -f xhtml

PhD's rendering options

Let's take a closer look at PhD and see what capabilities are available to us.

$ php phd/render.php --help
PhD version: 1.1.12
Copyright(c) 2007-2024 The PHP Documentation Group

    -v
    --verbose <int>            Adjusts the verbosity level
    -f <formatname>
    --format <formatname>      The build format to use
    -P <packagename>
    --package <packagename>    The package to use
    -I
    --noindex                  Do not index before rendering but load from cache
                                (default: false)
    -M
    --memoryindex              Do not save indexing into a file, store it in memory.
                                (default: false)
    -r
    --forceindex               Force re-indexing under all circumstances
                                (default: false)
    -t
    --notoc                    Do not rewrite TOC before rendering but load from
                                cache (default: false)
    -d <filename>
    --docbook <filename>       The Docbook file to render from
    -x
    --xinclude                 Process XML Inclusions (XInclude)
                                (default: false)
    -p <id[=bool]>
    --partial <id[=bool]>      The ID to render, optionally skipping its children
                                chunks (default to true; render children)
    -s <id[=bool]>
    --skip <id[=bool]>         The ID to skip, optionally skipping its children
                                chunks (default to true; skip children)
    -l
    --list                     Print out the supported packages and formats
    -o <directory>
    --output <directory>       The output directory (default: .)
    -F filename
    --outputfilename filename  Filename to use when writing standalone formats
                                (default: <packagename>-<formatname>.<formatext>)
    -L <language>
    --lang <language>          The language of the source file (used by the CHM
                                theme). (default: en)
    -c <bool>
    --color <bool>             Enable color output when output is to a terminal
                                (default: true)
    -C <filename>
    --css <filename>           Link for an external CSS file.
    -g <classname>
    --highlighter <classname>  Use custom source code highlighting php class
    -V
    --version                  Print the PhD version information
    -h
    --help                     This help
    -e <extension>
    --ext <extension>          The alternative filename extension to use,
                                including the dot. Use 'false' for no extension.
    -S <bool>
    --saveconfig <bool>        Save the generated config (default: false).

    -Q
    --quit                     Don't run the build. Use with --saveconfig to
                                just save the config.
    -k
    --packagedir               Use an external package directory.

As you can see, there are plenty of options to look into in PhD. The most important options are those which allow you to select a format and package to output your documentation to.

$ php phd/render.php --list
Supported packages:
        Generic
                xhtml
                bigxhtml
                manpage
        IDE
                xml
                funclist
                json
                php
                phpstub
        PEAR
                xhtml
                bigxhtml
                php
                chm
                tocfeed
        PHP
                xhtml
                bigxhtml
                php
                howto
                manpage
                pdf
                bigpdf
                kdevelop
                chm
                tocfeed
                epub
                enhancedchm

To select a format and package, you must use the -f [formatName] and -P [packageName] options.

E.g.: to generate the documentation in the same format used on php.net, use the PHP package's php format.

$ php phd/render.php -d .manual.xml -P PHP -f php

Syntax highlighting

Part of the documentation of programming languages is source code examples. PhD is able to colorize the source code of many types of source code with the help of highlighters.

To utilize syntax highlighting, your opening <programlisting> tags need a role attribute describing the type of source code. Examples are php, html and python.

NOTE: PhD currently only highlights the code if it is embedded in a CDATA section.

<programlisting role="php"><![CDATA[
<?php
echo "Hello world!";
?>
]]></programlisting>

By default, PhD uses the source code highlighter that is built into PHP itself which is only able to highlight PHP code.

If your documentation contains other types of source code or markup, you can write a custom syntax highlighter.

Writing a custom syntax highlighter

A syntax highlighter for PhD is nothing more than a simple PHP class that has two methods: factory and highlight.

factory is static, takes the format name (i.e. pdf, xhtml, troff) as its only parameter and returns the highlighter instance object for the given format. The method is called for each output format the documentation is rendered to.

highlight takes three parameters: text, role and format. It is called whenever a piece of source code needs to be highlighted and expects the highlighted source code to be returned in the format of the current rendering format.

Take a look at the provided highlighters, phpdotnet\phd\Highlighter, phpdotnet\phd\Highlighter_GeSHi and phpdotnet\phd\Highlighter_GeSHi11x. They will serve as good examples on how to implement your own highlighter.

Once you wrote your custom source code highlighting class, it's time to try it out.

phd's People

Contributors

alfsb avatar andyburton avatar bjori avatar bolechen avatar cmb69 avatar crell avatar cweiske avatar derickr avatar felipensp avatar girgias avatar haszi avatar kallez avatar kocsismate avatar lawngnome avatar mallardduck avatar moacir avatar mumumu avatar nilgun avatar petk avatar philip avatar sad-spirit avatar salathe avatar saltybeagle avatar simionea avatar sobak avatar steelywing avatar sy-records avatar timwolla avatar tpunt avatar vrana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phd's Issues

Foreign return type syntax

I noticed that the documentation still uses Java/C# style return types, even though PHP now has its own syntax for return types. For exmaple:

mixed json_decode ( string $json )

instead of:

json_decode ( string $json ) : mixed

It would be nice to see the documentation reflect the syntax of the language.

Speed up or avoid downloading of css from http://www.php.net in render.php

When running phd/render.php --docbook doc-base/.manual.xml --package PHP --partial=book.simdjson --format xhtml - it takes 10 seconds

Using https://github.com/adsr/phpspy to render a flame graph:

phd-flame-graph

  1. Use php's curl module if available?
  2. Use a different CDN for static assets if possible, or check if the file is recent? (This is taking 5 seconds per file, which is a different question for a different repo)
  3. Send etags/if-modified-since? (doesn't help, still slow https://daniel.haxx.se/blog/2019/12/06/curl-speaks-etag/ )
  4. It's a fast 0.01 second redirect to https://www.php.net/styles/theme-base.css
  5. Maybe check the modification time on disk and cache on disk as sha($url) on http 200s, and allow it by default if the css file modification time is less than a day old
Copying http://www.php.net/styles/theme-base.css
Copying http://www.php.net/styles/theme-medium.css
» wc output/php-chunked-xhtml/**/*.css  
 1884  3784 32631 output/php-chunked-xhtml/styles/03e73060321a0a848018724a6c83de7f-theme-base.css
  606  1242 11091 output/php-chunked-xhtml/styles/03e73060321a0a848018724a6c83de7f-theme-medium.css
 2490  5026 43722 total
< HTTP/2 200 
< server: myracloud
< date: Fri, 21 Oct 2022 12:52:18 GMT
< content-type: text/css
< last-modified: Mon, 17 Oct 2022 12:10:02 GMT
< etag: "634d461a-7f77"
< expires: Sat, 22 Oct 2022 11:06:08 GMT
< cache-control: max-age=86400
< x-cdn: 1

This might just be a wifi or cdn or isp issue, though - see php/web-php#556

Submit package to Packagist

The repository contains a valid composer.json file, so the package could be installed via Composer, however attempting to composer require php/phd lists that the package could not be found.

Attempting to submit the package via https://packagist.org/packages/submit gives "The vendor name php is reserved, please use another name or reach out to us if you have a legitimate use for it."

Broken links for constants in table rows

Hi,

The links to constants in https://www.php.net/manual/en/class.phar.php are broken (e.g., https://www.php.net/manual/en/.php#phar.constants.sha256 )

While they point to the correct ids it seems the URLs for Ids inside table.row are not being generated correctly.

en/reference/phar/Phar.xml
121:     <varname linkend="phar.constants.sha256">Phar::SHA256</varname>

en/reference/phar/constants.xml
117:     <row xml:id="phar.constants.sha256">

While the code lies in the doc-en repository, I suppose this is a URL generation issue with phd (?)

Function listing in PHP manual contains spurious entries for some languages

The Function and Method listing contains spurious entries at the end for some languages, e.g. Japanese and simplified Chinese. I think this is (at least partially) caused by not properly handling UTF-8, e.g.

// Nav bar to jump directly to a character
$chars = array_count_values(array_map(function($ref){ return strtolower($ref[0]); }, $refs));

I'm not really sure whether this is the actual issue, though, since only functions and methods are supposed to be listed there, and this should only contain valid ASCII characters, so strlower() and friends shouldn't be a problem.

Publish a new release on PEAR and github?

https://github.com/php/phd/releases mentions the last release was 1.1.11, from 2019. Various improvements were made on the master branch since then (e.g. fixing various notices uses of deprecated features such as join() argument order).

https://wiki.php.net/doc/phd/install mentions that "The preferred method is using the pear channel", which also causes 1.1.11 to be installed.

I'm not familiar with publishing of pear modules myself, or who would be considered an owner of this application. Going through the steps in https://github.com/php/phd/blob/master/HOWTO.RELEASE first would help (e.g. checking for missing files and putting release notes in package.xml)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.