Fork me on GitHub

Usage


1. Installation

1.1 Common install

SkrivMarkup can be installed using Composer.

In your project directory, create a composer.json file:

{
    "require": {
        "amaury/wikirenderer": "dev-master",
        "amaury/skrivmarkup": "dev-master"
    }
}

Then, use Composer to fetch packages:

php composer.phar install

After that, all you need is to include the autoloader script provided by Composer. Starts your scripts like that:

<?php
require_once('vendor/autoload.php');

1.2 Syntax highlighting

If you want to activate source code syntax highlighting, you must install the Generic Syntax Highlighter library.

You just have to add a line in the composer.json file:

{
    "require": {
        "amaury/wikirenderer": "dev-master",
        "amaury/skrivmarkup": "dev-master",
        "easybook/geshi": "dev-master"
    }
}

And that's it. Syntax highlighting will work without any hassle.

2. HTML Rendering

Once SkrivMarkup installed, it is very easy to generate some HTML from a Skriv Markup text.

<?php
require_once('vendor/autoload.php');

// creation of the renderer object
$renderer = \Skriv\Markup\Renderer::factory();

// text to HTML processing
$text = "Some **Skriv** ''enabled'' text.";
$html = $renderer->render($text);

print($html);

Result:

<p>
    Some <strong>Skriv</strong> <em>enabled</em> text.
</p>

3. Table of Contents

It is possible to get the table of contents, generated from a document titles. By default, SkrivMarkup returns an HTML version of the ToC, but it is also possible to get a raw version (PHP arrays).

$renderer = \Skriv\Markup\Renderer::factory();

$text = "=Low=
==Old==
===Commodore 64===
===Atari 400XL===
==Recent==
===Asus EeePC===
=Medium=
==Old==
===Commodore Amiga===
===Apple Macintosh===
==Recent==
===Asus ZenBook===";
$html = $renderer->render($text);

$tocHtml = $renderer->getToc();
$tocRaw = $renderer->getToc(true);

print($tocHtml);
print_r($tocRaw);

3.1 HTML Result

The HTML output is constitutued of lists and sublists, with links to anchored titles.

<ul class="toc-list">
  <li class="toc-entry"><a href="#Low">Low</a>
    <ul class="toc-list">
      <li class="toc-entry"><a href="#Old">Old</a>
        <ul class="toc-list">
          <li class="toc-entry"><a href="#Commodore-64">Commodore 64</a></li>
          <li class="toc-entry"><a href="#Atari-400XL">Atari 400XL</a></li>
        </ul>
      </li>
      <li class="toc-entry"><a href="#Recent">Recent</a>
        <ul class="toc-list">
          <li class="toc-entry"><a href="#Asus-EeePC">Asus EeePC</a></li>
        </ul>
      </li>
    </ul>
  </li>
  <li class="toc-entry"><a href="#Medium">Medium</a>
    <ul class="toc-list">
      <li class="toc-entry"><a href="#Old">Old</a>
        <ul class="toc-list">
          <li class="toc-entry"><a href="#Commodore-Amiga">Commodore Amiga</a></li>
          <li class="toc-entry"><a href="#Apple-Macintosh">Apple Macintosh</a></li>
        </ul>
      </li>
      <li class="toc-entry"><a href="#Recent">Recent</a>
        <ul class="toc-list">
          <li class="toc-entry"><a href="#Asus-ZenBook">Asus ZenBook</a></li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

3.2 Raw Result

The raw output is a PHP array of associative arrays. Each node contains an id and a value keys, and an optional sub key.

  • id: The generated DOM identifier of the title; could be used to create a link pointing to the title entry.
  • value: The title's text.
  • sub: An array of sub-nodes.
Array(
    [0] => Array(
        [id] => Low
        [value] => Low
        [sub] => Array(
            [0] => Array(
                [id] => Old
                [value] => Old
                [sub] => Array(
                    [0] => Array(
                        [id] => Commodore-64
                        [value] => Commodore 64
                    )
                    [1] => Array(
                        [id] => Atari-400XL
                        [value] => Atari 400XL
                    )
                )
            )
            [1] => Array(
                [id] => Recent
                [value] => Recent
                [sub] => Array(
                    [0] => Array(
                        [id] => Asus-EeePC
                        [value] => Asus EeePC
                    )
                )
            )
        )
    )
    [1] => Array(
        [id] => Medium
        [value] => Medium
        [sub] => Array(
            [0] => Array(
                [id] => Old
                [value] => Old
                [sub] => Array(
                    [0] => Array(
                        [id] => Commodore-Amiga
                        [value] => Commodore Amiga
                    )
                    [1] => Array(
                        [id] => Apple-Macintosh
                        [value] => Apple Macintosh
                    )
                )
            )
            [1] => Array(
                [id] => Recent
                [value] => Recent
                [sub] => Array(
                    [0] => Array(
                        [id] => Asus-ZenBook
                        [value] => Asus ZenBook
                    )
                )
            )
        )
    )
)

4. Footnotes

When a text contains footnotes, it is possible to fetch them. Like tables of contents, footnotes can be retrieved as HTML stream or as raw PHP lists.

$renderer = \Skriv\Markup\Renderer::factory();

$text = "Arthur C. Clarke is one of the best SF author ((just after Issac Asimov)).

The Ford T is the car of the century ((Source|ahead Mini and Citroën DS, see
[[Wikipedia|http://en.wikipedia.org/wiki/Car_of_the_Century]])), but everybody knows
it should be the VW Beetle (([[Wikipedia|
http://en.wikipedia.org/wiki/Volkswagen_Beetle]])).";
$html = $renderer->render($text);
print($html);

$tocHtml = $renderer->getFootnotes();
$tocRaw = $renderer->getFootnotes(true);

print($tocHtml);
print_r($tocRaw);

HTML document:

<p>Arthur C. Clarke is one of the best SF author <sup><a href="#cite_note-1"
id="cite_ref-1">1</a></sup>.</p>

<p>The Ford T is the car of the century <sup><a href="#cite_note-2"
id="cite_ref-2">Source</a></sup>, but everybody knows it should be the VW Beetle
<sup><a href="#cite_note-3" id="cite_ref-3">3</a></sup>.</p>

4.1 HTML Result

<div class="footnotes">
    <p class="footnote">
        <a href="#cite_ref-1" id="cite_note-1">1</a>. just after Issac Asimov
    </p>
    <p class="footnote">
        <a href="#cite_ref-2" id="cite_note-2">Source</a>. ahead Mini and Citroën DS, see <a href="http://en.wikipedia.org/wiki/Car_of_the_Century">Wikipedia</a>
    </p>
    <p class="footnote">
        <a href="#cite_ref-3" id="cite_note-3">3</a>. <a href="http://en.wikipedia.org/wiki/Volkswagen_Beetle">Wikipedia</a>
    </p>
</div>

4.2 Raw Result

Array
(
    [0] => just after Issac Asimov
    [Source] => ahead Mini and Citroën DS, see <a href="http://en.wikipedia.org/wiki/Car_of_the_Century">Wikipedia</a>
    [2] => <a href="http://en.wikipedia.org/wiki/Volkswagen_Beetle">Wikipedia</a>
)