Go to file
Raphaël Jakse 8e631b0fa6 Update INSTALL instructions 2021-01-10 22:49:16 +01:00
plugins/dotclear initial commit 2014-03-17 09:51:46 +01:00
share fix revamp margins 2016-04-02 11:39:19 +02:00
whata-old initial commit 2014-03-17 09:51:46 +01:00
INSTALL Update INSTALL instructions 2021-01-10 22:49:16 +01:00
Makefile fix chmod+x htmlwhata when installing 2015-07-26 15:13:20 +02:00
README Fix required parameters following optional parameters (PHP 8 warnings) 2020-12-23 10:07:58 +01:00
config.php Allow loading GeSHi from different places 2020-12-23 09:41:49 +01:00
htmlwhata Better handling of --help 2020-12-23 09:52:53 +01:00
htmlwhata-tools.php Fix required parameters following optional parameters (PHP 8 warnings) 2020-12-23 10:07:58 +01:00
optimize_indentation.php add external dependency optimize_indentation.php 2014-03-20 12:02:25 +01:00
simplex.php initial commit 2014-03-17 09:51:46 +01:00
whata2html.php Fix required parameters following optional parameters (PHP 8 warnings) 2020-12-23 10:07:58 +01:00
whatadom.php fix paths for part: links 2016-04-02 11:41:21 +02:00

README

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

= Introduction

    This is whata-php, a parser for the [whata] Syntax.

    - ``whatadom.php`` is the part which translates a [whata] document to a tree representation.
        Here is an example of usage from a PHP script :
        [code=php <<<
            // Your document:
            whataDoc = '...';

            // you can override the default configuration by setting the
            // $whata_override_conf array so every call of whata will use
            // the supplied configuration by default:

            $whata_override_conf = array(
                'MATH_METHOD'   => 'function',
                'MATH_FUNCTION' => 'whata_MathJax',
                'GESHI_URL'     => 'geshi/geshi.php'
            );
            // obviously, this is not mandatory.

            include('whata-php/whatadom.php');

            $conf = array(
                'lang'   => 'en',
                'xhtml'  => true,
                'html5'  => true,
                'imgdir' => '/images/'
            );
            // Passing the $conf array is optional.
            // see later for the explanations on the $conf array.

            $dom = whataDOM($whataDoc, $conf);

            print_r($dom); // this outputs a huge amount of data
        >>>]

    - ``whata2html.php`` is the part which translates the tree representation of a document to HTML. It also has a convenient function which translates a [whata] document directly to HTML, which most people will want to do.

        - Usage 1 : Replace the last line of the last snippet of code by : [code=php <<< echo whatadom2html($dom, $conf); >>>]
        - Usage 2 (more direct) :

            [code=php <<<
                // Your document:
                whataDoc = '...';

                // ... the same as the last snippet ...

                include('whata-php/whata2html.php');

                $conf = array(
                    'lang'   => 'en',
                    'xhtml'  => true,
                    'html5'  => true,
                    'imgdir' => '/images/',
                    'processFootnotes' => true
                );
                // Passing the $conf array is optional.
                // see later for the explanations on the $conf array.

                echo whata2html($whataDoc, $conf);
            >>>]
        - Usage 3 (footnotes treated separately, getting further informations on the document, handling mathematics) :

            [code=php <<<
                // Your document:
                whataDoc = '...';

                // ... the same as the last snippet ...

                include('whata-php/whata2html.php');

                $conf = array(
                    'lang'   => 'en',
                    'xhtml'  => true,
                    'html5'  => true,
                    'imgdir' => '/images/',
                    'processFootnotes' => false // footnotes are separated
                                                // from the document
                );

                // Passing the $conf array is optional.
                // see later for the explanations on the $conf array.

                $html = whata2html($whataDoc, $conf);

                if ($conf['needMaths']) {
                    // Mathematics were used in the document. If you are using
                    // the MathJax method for displaying maths, you should
                    // include MathJax in your HTML document:

                    $https = true;

                    $mathJaxPath = $https ?
                        ? 'https://cdn.mathjax.org/mathjax/latest'
                        : 'http://cdn.mathjax.org/mathjax/latest';

                    echo '<script type="text/javascript" src="'
                                   . $mathJaxPath .
                         '/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
                        <script>
                            MathJax.Hub.Config({
                                tex2jax: {
                                inlineMath : [],
                                displayMath : [],
                                ignoreClass: "tex2jax_ignore",
                                processClass: "tex2jax_process",
                            //  preview: "none",
                                preferredFont: "STIX",
                                processEnvironments: false
                                }
                            });
                        </script>';
                }

                /* you can get the title, the author or the date of the document is you want to. */
                if (isset($conf['sets']['title'])) {
                    echo '<p>Title of the document : ', whatadom2html($conf['sets']['title'], WHATAHTML_INLINE, $conf), '</p>';
                }

                if (isset($conf['sets']['author'])) {
                    echo '<p>Author of the document : ', whatadom2html($conf['sets']['author'], WHATAHTML_INLINE, $conf), '</p>';
                }

                if (isset($conf['sets']['date'])) {
                    echo '<p>Date of the document : ', whatadom2html($conf['sets']['date'], WHATAHTML_INLINE, $conf), '</p>';
                }

                echo $html;

                // process footnotes separately here
                $footnotes = whatahtml_process_footnotes($conf);
                echo $footnotes;
            >>>]

            Any value present in the [set ] tag for the document can be retrieved like in the last snippet.

            If you need a block instead of inline HTML behavior, you can use ``0`` instead of ``WHATAHTML_INLINE``.

            if you need a raw string rather than an HTML string, you can use the ``whata_text_content()`` function of ``whatadom.php``:

            [code=php <<<
                echo '<p> Date of the document, as text: ', htmlspecialchars(whata_text_content($conf['sets']['date'])), '</p>';
            >>>]

    - ``htmlwhata-tools.php`` is a chunk of code which in theory helps in generating good documents from templates and which is configurable. See ``htmlwhata`` for an example of usage.
    - ``htmlwhata`` is a program (PHP script in command line) for translating [whata] document into complete HTML documents and supports templates / config options.
= The ``$conf`` array.

    ``$conf`` is an associative array which can optionaly be passed to ``whatadom``, ``whatadom2html`` and ``whata2html``.

    The following values are recognized by ``whatadom``:

    - ``basedir``: the path to files or documents referenced by relative links in [whata] documents
    - ``imgdir``:  the path to the images directory. Defaults to ``basedir``
    - ``xhtml``:   if true, will generate a XHTML-valid document. Default to ``false``.
    - ``html5``:   if true, will use HTML5 tags. Defaults to ``true``.
    - ``linkToWhataPrefix``: string to prepend to document names referenced in links like ``doc:your-document`` or ``part=your-document``. Defaults to the empty string.
    - ``linkToWhataSuffix``: string to append to document names referenced in links like ``doc:your-document`` or ``part=your-document``. Defaults to ``.xhtml`` if xhtml is true, ``.html`` otherwise.
    - ``docRefCallback``: callback function which will be called each time another [whata] document is referenced in the document. Passed parameters are :
        - the path to the [whata] file
        - the URL which is used in the generated document to access the referenced document (using ``linkToWhataPrefix`` and ``linkToWhataSuffix``).
    - ``lang``: the language in which the document is written.

    ``whata2html`` calls ``whataDOM`` so it understands all the previous options. It also calls ``whatadom2html`` which understands the additional following options: (to be writen)

= PHP 8 Support

Whata works on PHP8, but GeSHi is untested and may not work on this version.