From cdbe8eedd5bc4dd309712a31b32d3842c02034a5 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 3 Apr 2007 20:06:32 +0000 Subject: [PATCH] Added a system to extract the link map... --- Markdown.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Markdown.php b/Markdown.php index 1a02235..2481b3f 100644 --- a/Markdown.php +++ b/Markdown.php @@ -66,6 +66,12 @@ class BSMarkdown 'noscript' ); + /** + * Map of link IDs to their link + * @var string + */ + private $linkMap = array(); + // ################################################################### /** * Quick parsing function that uses the system defaults for parsing. @@ -108,6 +114,7 @@ class BSMarkdown $this->text = preg_replace('/^\s*?$/m', '', $this->text); $this->_extractHtmlBlocks(); + $this->_extractLinkMap(); $this->_convertHardLineBreaks(); $this->_convertAtxHeaders(); @@ -174,6 +181,26 @@ class BSMarkdown return str_replace(array_keys($this->htmlBlockMap), array_values($this->htmlBlockMap), $text); } + // ################################################################### + /** + * Extracts all links in the "[id]: link" form + */ + public function _extractLinkMap() + { + $this->text = preg_replace_callback('/\[(\w+)\]:\s*?(\s*(("|\')|\()(.*?)(\4|\)))?\n?/', array(&$this, '_extractLinkMapCallback'), $this->text); + } + + // ################################################################### + /** + * Converts extracted link definitions into the map + * + * @param array Matches array + */ + private function _extractLinkMapCallback($matches) + { + $this->linkMap[$matches[1]] = array($matches[2], $matches[6]); + } + // ################################################################### /** * Converts text surrounded by #sings to headers (## Heading 2) @@ -191,7 +218,7 @@ class BSMarkdown */ private function _convertAtxHeadersCallback($matches) { - var_dump($matches); + // var_dump($matches); $html = '' . $this->_expandHtmlBlocks($matches[2]) . ''; $hash = md5($html . microtime()); $this->htmlBlockMap[$hash] = $html; -- 2.43.5