Diffs
HatenaSyntax/trunk/test/RelativeLink.php
@@ -1,24 +0,0 @@
-<?php
-include_once dirname(__FILE__) . '/t/t.php';
-
-$lime = new lime_test;
-$parser = HatenaSyntax_Locator::it()->link;
-
-//--
-
-$context = PEG::context('[[keyword]]');
-$result = $parser->parse($context);
-$lime->is($result->getType(), 'relativelink');
-$lime->is($result->getData(), 'keyword');
-
-//--
-
-$context = PEG::context('[[javascript:alert(\'hahaha\')]]');
-$result = $parser->parse($context);
-$lime->is($result, PEG::failure());
-
-//--
-
-$context = PEG::context('[[ javascript:alert(\'hahaha\')]]');
-$result = $parser->parse($context);
-$lime->is($result, PEG::failure());
\ ファイルの末尾に改行がありません
HatenaSyntax/trunk/test/KeywordLink.php
@@ -0,0 +1,24 @@
+<?php
+include_once dirname(__FILE__) . '/t/t.php';
+
+$lime = new lime_test;
+$parser = HatenaSyntax_Locator::it()->link;
+
+//--
+
+$context = PEG::context('[[keyword]]');
+$result = $parser->parse($context);
+$lime->is($result->getType(), 'keywordlink');
+$lime->is($result->getData(), 'keyword');
+
+//--
+
+$context = PEG::context('[[javascript:alert(\'hahaha\')]]');
+$result = $parser->parse($context);
+$lime->is($result, PEG::failure());
+
+//--
+
+$context = PEG::context('[[ javascript:alert(\'hahaha\')]]');
+$result = $parser->parse($context);
+$lime->is($result, PEG::failure());
\ ファイルの末尾に改行がありません
HatenaSyntax/trunk/sample/sample1.php
@@ -17,7 +17,7 @@
-list6
paragraph((footnote))
-[[relativelink]]
+[[keywordlink]]
[][[nulllink]][]
|*table header |*table header2 |
@@ -50,14 +50,20 @@
. '">' . PHP_EOL . $body . '</pre>';
}
+function keywordlinkhandler($path)
+{
+ return './' . $path;
+}
+
// オプションは全て省略可。第二引数自体も省略可。
-echo HatenaSyntax::render($str, array('headerlevel' => 3, // ヘッダの基準値。デフォルトは1
- 'id' => 'hoge', // 記事の識別子。指定しない場合はランダムなIDが生成される
- 'htmlescape' => false, // デフォルトはtrue。
- 'sectionclass' => 'section', // 記事本体を囲むdiv要素のクラス。デフォルトは'section'
- 'footnoteclass' => 'footnote', // 脚注を囲むdiv要素のクラス。デフォルトは'footnote'
- 'superprehandler' => 'sprehandler')); // superpre記法の中身を処理するコールバック。
-/*
+echo HatenaSyntax::render($str, array('headerlevel' => 3, // ヘッダの基準値。デフォルトは1
+ 'id' => 'hoge', // 記事の識別子。指定しない場合はランダムなIDが生成される
+ 'htmlescape' => false, // デフォルトはtrue。
+ 'sectionclass' => 'section', // 記事本体を囲むdiv要素のクラス。デフォルトは'section'
+ 'footnoteclass' => 'footnote', // 脚注を囲むdiv要素のクラス。デフォルトは'footnote'
+ 'keywordlinkhanlder' => 'keywordlinkhandler', // キーワード記法のキーワードをアドレスに処理するコールバック
+ 'superprehandler' => 'sprehandler')); // superpre記法の中身を処理するコールバック
+/* 結果
<div class="section">
<h3>header1</h3>
@@ -83,7 +89,7 @@
</ul>
<p>paragraph(<a href="#hoge_footnote_1" name="hoge_1" title="footnote">*1</a>)</p>
- <p><a href="relativelink">relativelink</a></p>
+ <p><a href="./keywordlink">keywordlink</a></p>
<p>[[nulllink]]</p>
<table>
HatenaSyntax/trunk/code/HatenaSyntax/Locator.php
@@ -96,13 +96,13 @@
return $this->factory->createNodeCreater('imagelink', $parser);
}
- protected function createRelativeLink()
+ protected function createKeywordLink()
{
- $body = PEG::join(PEG::many1(PEG::subtract(PEG::anything(), PEG::newLine(), ']]', ' ', "\t")));
- $body = PEG::subtract($body, 'javascript:');
+ $body = PEG::join(PEG::many1(PEG::subtract(PEG::anything(), PEG::newLine(), ']]')));
+ $body = PEG::subtract($body, 'javascript:', ' ', "\t");
$parser = PEG::pack('[', $body, ']');
- return $this->factory->createNodeCreater('relativelink', $parser);
+ return $this->factory->createNodeCreater('keywordlink', $parser);
}
protected function createNullLink()
@@ -115,7 +115,7 @@
protected function createLink()
{
- return PEG::pack('[', PEG::choice($this->nullLink, $this->relativeLink, $this->imageLink, $this->httpLink), ']');
+ return PEG::pack('[', PEG::choice($this->nullLink, $this->keywordLink, $this->imageLink, $this->httpLink), ']');
}
protected function createDefinition()
HatenaSyntax/trunk/code/HatenaSyntax/Renderer.php
@@ -18,6 +18,7 @@
'id' => uniqid('sec'),
'sectionclass' => 'section',
'footnoteclass' => 'footnote',
+ 'keywordlinkhandler' => array($this, 'keywordLinkHandler'),
'superprehandler' => array($this, 'superPreHandler')
);
}
@@ -44,6 +45,11 @@
return '<pre class="superpre">' . PHP_EOL . $body . '</pre>';
}
+ static function keywordLinkHandler($path)
+ {
+ return './' . $path;
+ }
+
protected function renderNode(HatenaSyntax_Node $node)
{
$this->padding++;
@@ -104,10 +110,11 @@
return '<a href="' . $url . '"><img src="' . $url . '" /></a>';
}
- protected function renderRelativeLink($path)
+ protected function renderKeywordLink($path)
{
$path = self::escape($path);
- return '<a href="' . $path . '">' . $path . '</a>';
+ $href = call_user_func($this->config['keywordlinkhandler'], $path);
+ return '<a href="' . $href . '">' . $path . '</a>';
}
protected function renderDefinitionList(Array $data)