X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=mdref%2FReference.php;h=892be7e096ab8da0f66e140bbd39dc4f2a53d8e4;hb=80ea76521e2ccbbfac1ac0f33f91af1739ead561;hp=153004fdafc83dd75ea4e072fcad0c1afcc298a8;hpb=6478b415c59070f70ed860f3a592377eef9783b1;p=mdref%2Fmdref diff --git a/mdref/Reference.php b/mdref/Reference.php index 153004f..892be7e 100644 --- a/mdref/Reference.php +++ b/mdref/Reference.php @@ -11,7 +11,7 @@ class Reference implements \IteratorAggregate { * @var array */ private $repos = array(); - + /** * @param array $refs list of mdref repository paths */ @@ -21,7 +21,7 @@ class Reference implements \IteratorAggregate { $this->repos[$repo->getName()] = $repo; } } - + /** * Lookup the repo containing a ref entry * @param string $entry requested reference entry, e.g. "pq/Connection/exec" @@ -35,7 +35,7 @@ class Reference implements \IteratorAggregate { } } } - + /** * Implements \IteratorAggregate * @return \ArrayIterator repository list @@ -43,5 +43,26 @@ class Reference implements \IteratorAggregate { public function getIterator() { return new \ArrayIterator($this->repos); } - + + public function formatAnchor($anchor) { + if (is_numeric($anchor)) { + return "L$anchor"; + } + return preg_replace("/[^[:alnum:]\.:_]/", ".", $anchor); + } + + public function formatString($string) { + $md = \MarkdownDocument::createFromString($string); + $md->compile(\MarkdownDocument::AUTOLINK); + return $md->getHtml(); + } + + public function formatFile($file) { + $fd = fopen($file, "r"); + $md = \MarkdownDocument::createFromStream($fd); + $md->compile(\MarkdownDocument::AUTOLINK | \MarkdownDocument::TOC); + $html = $md->getHtml(); + fclose($fd); + return $html; + } }