Skip to content

Commit

Permalink
Update tag inventory of Inigo renderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
mermshaus committed Mar 22, 2016
1 parent 058db46 commit cb46a00
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -43,6 +43,7 @@ Available tags:
* `quote` (`=@author`)
* `off`|`noparse`
* `var`
* `indent`, `center`
* `url`|`link` (`=@href`, `@title`)
* `img` (`=@src`)
* `abbr` (`=@title`)
Expand Down
12 changes: 12 additions & 0 deletions demos/renderer/inigo.txt
Expand Up @@ -24,3 +24,15 @@ Klar ist wohl, dass das Fehlen von Stable-Versionen auf Packagist die Nutzung vo
Was tun?

[strike]Edit: Vielleicht könnte man mit dem version-Feld in der composer.json-Datei von GeSHi was machen. Von der Nutzung wird zwar zugunsten von Tags abgeraten, aber Tags fallen ja in diesem Fall vermutlich raus. Hat damit jemand Erfahrung? Naheliegende Frage wäre etwa: Wenn ich bei Commit #1 in composer.json [I]"version": "1.0"[/I] stehen habe und das bei Commit #2 nicht ändere, ist dann auf Packagist Commit #1 oder Commit #2 mit dem 1.0-Release verknüpft? Das kann ich aber nachher einfach mal ausprobieren.[/strike] [INDENT]Okay, das funktoniert nicht, weil Packagist ausschließlich Tags erkennt: [URL="https://github.com/composer/packagist/issues/587#issuecomment-142686483"]https://github.com/composer/packagis...ment-142686483[/URL][/INDENT]

[center]* * *[/center]

[quote=mermshaus]Ich glaube, es gibt wirklich nur die Optionen,

[ol]
[li]geshi/geshi zusätzlich mit Packagist-kompatiblen Tags auszustatten,[/li]
[li]ein neues Repository zu starten und in dem auf irgendeine Weise den Code aus geshi/geshi zu mirrorn und dort passende Tags hinzuzufügen (da gibt es etwa: https://packagist.org/packages/easybook/geshi – ohne Gewähr) oder[/li]
[li]geshi/geshi weiterhin von Hand im obersten Projekt-Repository einzubinden (wie in Post #1).[/li]
[/ol]

Die haben für mich alle Vor- und Nachteile.[/quote]
46 changes: 46 additions & 0 deletions src/Inigo/Handler/QuoteHandler.php
@@ -0,0 +1,46 @@
<?php

namespace Kaloa\Renderer\Inigo\Handler;

use Kaloa\Renderer\Inigo\Handler\ProtoHandler;
use Kaloa\Renderer\Inigo\Parser;

/**
*
*/
final class QuoteHandler extends ProtoHandler
{
/**
*
*/
public function __construct()
{
$this->name = 'quote';
$this->type = Parser::TAG_OUTLINE | Parser::TAG_FORCE_PARAGRAPHS;
$this->defaultParam = 'author';
}

/**
*
* @param array $data
* @return string
*/
public function draw(array $data)
{
$ret = '';

if ($data['front']) {
$author = $this->fillParam($data, 'author', '');

if ('' !== $author) {
$ret .= '<p>' . $this->e($author) . ':</p>' . "\n\n";
}

$ret .= '<blockquote>' . "\n";
} else {
$ret .= '</blockquote>' . "\n\n";
}

return $ret;
}
}
18 changes: 10 additions & 8 deletions src/Inigo/Parser.php
Expand Up @@ -10,6 +10,7 @@
use Kaloa\Renderer\Inigo\Handler\HTMLHandler;
use Kaloa\Renderer\Inigo\Handler\ImgHandler;
use Kaloa\Renderer\Inigo\Handler\ProtoHandler;
use Kaloa\Renderer\Inigo\Handler\QuoteHandler;
use Kaloa\Renderer\Inigo\Handler\SimpleHandler;
use Kaloa\Renderer\Inigo\Handler\UrlHandler;
use Kaloa\Renderer\Inigo\Handler\YouTubeHandler;
Expand Down Expand Up @@ -76,12 +77,14 @@ public function addDefaultHandlers(Config $config)

->addHandler(new SimpleHandler('off|noparse', Parser::TAG_INLINE | Parser::TAG_PRE, '', ''))
->addHandler(new SimpleHandler('var', Parser::TAG_INLINE | Parser::TAG_PRE, '<var>', '</var>'))
->addHandler(new SimpleHandler(
'quote',
Parser::TAG_OUTLINE | Parser::TAG_FORCE_PARAGRAPHS,
'<blockquote>',
"</blockquote>\n\n"
))
// ->addHandler(new SimpleHandler(
// 'quote',
// Parser::TAG_OUTLINE | Parser::TAG_FORCE_PARAGRAPHS,
// '<blockquote>',
// "</blockquote>\n\n"
// ))

->addHandler(new QuoteHandler())

/* Most replacements are rather simple */
->addHandler(new SimpleHandler('h1', Parser::TAG_OUTLINE, "<h1>", "</h1>\n\n"))
Expand All @@ -102,8 +105,7 @@ public function addDefaultHandlers(Config $config)
->addHandler(new SimpleHandler('th', Parser::TAG_OUTLINE, "\n<th>", "</th>"))

->addHandler(new SimpleHandler('indent', Parser::TAG_OUTLINE, "<div style=\"margin-left: 30px;\">", "</div>\n\n"))


->addHandler(new SimpleHandler('center', Parser::TAG_OUTLINE, "<div style=\"text-align: center;\">", "</div>\n\n"))

->addHandler(new UrlHandler())
->addHandler(new ImgHandler())
Expand Down
6 changes: 5 additions & 1 deletion tests/Kaloa/Tests/Renderer/examples/inigo/indent.expected
Expand Up @@ -5,4 +5,8 @@

</div>

</div>
</div>

<div style="text-align: center;">* * *</div>

<p>Foo</p>
4 changes: 4 additions & 0 deletions tests/Kaloa/Tests/Renderer/examples/inigo/indent.txt
Expand Up @@ -4,3 +4,7 @@ bar

[indent][h3]baz & boz[/h3][/indent]
[/indent]

[center]* * *[/center]

Foo
22 changes: 22 additions & 0 deletions tests/Kaloa/Tests/Renderer/examples/inigo/quotations.expected
@@ -0,0 +1,22 @@
<p>Other text.</p>
<blockquote>
<p>This is a test</p>
</blockquote>

<p>Other text.</p>
<blockquote>
<p>This is another test.</p>

<p>With two paragraphs.</p>
</blockquote>

<p>Other text.</p>
<p>Foo &amp; Bar:</p>

<blockquote>
<p>This is.</p>

<p>A Test.</p>
</blockquote>

<p>Other text.</p>
17 changes: 17 additions & 0 deletions tests/Kaloa/Tests/Renderer/examples/inigo/quotations.txt
@@ -0,0 +1,17 @@
Other text.

[quote]This is a test[/quote]

Other text.

[quote]This is another test.

With two paragraphs.[/quote]

Other text.

[quote="Foo & Bar"]This is.

A Test.[/quote]

Other text.

0 comments on commit cb46a00

Please sign in to comment.