Esempio n. 1
0
include_once dirname(__FILE__) . '/../lib/HatenaSyntax.php';
$text = <<<EOS
*s1* hoge
a

*s2* fuga
b

*s3* piyo
c

EOS;
$nodes = HatenaSyntax::parseAsSections($text);
foreach ($nodes as $node) {
    $name = HatenaSyntax::getSectionName($node);
    echo "<!--{$name}-->\n";
    echo HatenaSyntax::renderNode($node);
    echo "\n";
}
/* 結果

<!--s1-->
<div class="section">
<h1> hoge<a name="0a5f00d24e95fc67f4933ba9d374a09f_header_0" id="0a5f00d24e95fc67f4933ba9d374a09f_header_0"></a></h1>
<p>a</p>

</div>

<!--s2-->
<div class="section">
Esempio n. 2
0
<?php

include_once dirname(__FILE__) . '/../t.php';
$t = new lime_test();
$hs = new HatenaSyntax();
$node = $hs->parse('*hoge*header');
$t->is($hs->getSectionName($node), 'hoge');
$node = $hs->parse('*hoge');
$t->is($hs->getSectionName($node), '');
$node = $hs->parse('**hoge*header');
$t->is($hs->getSectionName($node), '');
$node = $hs->parse('');
$t->pass();
$nodes = $hs->parseAsSections("\n*hoge\n*fuga\n*piyo");
$t->is(count($nodes), 3);
$nodes = $hs->parseAsSections("*hoge\n\nfuga");
$t->is(count($nodes), 1);
$title = $hs->getSectionTitle($hs->parse('*hahaha'));
$t->is($title, 'hahaha');
$title = $hs->getSectionTitle($hs->parse('*hoge*s[http://google.com]'));
$t->is($title, 'shttp://google.com');
$hasTopHeader = $hs->hasTopHeader($hs->parse('*hoge'));
$t->ok($hasTopHeader);
$hasTopHeader = $hs->hasTopHeader($hs->parse('hoge'));
$t->ok(!$hasTopHeader);
$hasSeparator = $hs->hasSeparator($hs->parse('* fuga'));
$t->ok(!$hasSeparator);
$hasSeparator = $hs->hasSeparator($hs->parse("* hoge\n====\nhahaha"));
$t->ok($hasSeparator);
$node = $hs->separate($hs->parse("* hoge\n====\nhahaha"));
$t->is(count($node->getData()), 2);