powered by nequal
Home » HatenaSyntax » Timeline » 1899

Changeset 1899 -- 2010-06-06 01:02:02

Author
anatoo
Comment
Added title paramater to blockquote's source url

Diffs

HatenaSyntax/trunk/test/lib/HatenaSyntax/Quote.php

@@ -17,15 +17,38 @@
array('a')
));
+
$c = PEG::context(array(
'>http://google.com>',
'a',
'<<'
));
-$t->is(
-    $p->parse($c),
-    array(
-        'http://google.com',
-        array('a')
-    ));
+$result = $p->parse($c);
+$t->is($result[1], array('a'));
+$t->is($result[0]->at('url'), 'http://google.com');
+$t->is($result[0]->at('title'), false);
+
+
+$c = PEG::context(array(
+    '>http://google.com:title>',
+    'a',
+    '<<'
+));
+
+$result = $p->parse($c);
+$t->is($result[1], array('a'));
+$t->is($result[0]->at('url'), 'http://google.com');
+$t->is($result[0]->at('title'), '');
+
+
+$c = PEG::context(array(
+    '>http://google.com:title=hoge>',
+    'a',
+    '<<'
+));
+
+$result = $p->parse($c);
+$t->is($result[1], array('a'));
+$t->is($result[0]->at('url'), 'http://google.com');
+$t->is($result[0]->at('title'), 'hoge');

HatenaSyntax/trunk/lib/HatenaSyntax/Quote.php

@@ -28,14 +28,27 @@
function mapHeader($line)
{
-        if (substr($line, 0, 1) !== '>') {
+        if (substr($line, 0, 1) !== '>' || substr($line, -1, 1) !== '>') {
return PEG::failure();
}
-        if (!preg_match('#^>(|https?://[^>]+)>$#', $line, $matches)) {
+        if ($line === '>>') {
+            return false;
+        }
+
+        $link_exp = substr($line, 1, strlen($line) - 2);
+
+        if (!preg_match('#^(https?://[^>:]+)(:title(=(.+))?)?$#', $link_exp, $matches)) {
return PEG::failure();
}
-        return $matches[1] === '' ? false : $matches[1];
+        $title = !isset($matches[2])
+            ? false
+            : (isset($matches[4]) ? $matches[4] : '');
+
+        return new HatenaSyntax_Node('httplink', array(
+            'href'   => $matches[1],
+            'title' => isset($matches[4]) ? $matches[4] : false)
+        );
}
}

HatenaSyntax/trunk/lib/HatenaSyntax/Renderer.php

@@ -273,7 +273,9 @@
$ret = array();
$ret[] = '<blockquote>';
foreach ($arr['body'] as $elt) $ret[] = $this->renderNode($elt);
-        if ($arr['url']) $ret[] = '<cite><a href="' . self::escape($arr['url']) . '">' . self::escape($arr['url']) . '</a></cite>';
+        if ($arr['url']) {
+            $ret[] = '<cite>' . $this->renderHttpLink($arr['url']->getData()) . '</cite>';
+        }
$ret[] = '</blockquote>';
return join(PHP_EOL, $ret);
}