From 8e861d340bae10f215c4aa15b363484bd33c2d3b Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Sun, 20 Apr 2008 23:17:15 -0400 Subject: [PATCH] Added setup and teardown methods for easy overriding. --- markdown.php | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/markdown.php b/markdown.php index 13781f5..d4e1c33 100644 --- a/markdown.php +++ b/markdown.php @@ -238,23 +238,38 @@ class Markdown_Parser { # Status flag to avoid invalid nesting. var $in_anchor = false; - - - function transform($text) { + + function setup() { # - # Main function. The order in which other subs are called here is - # essential. Link and image substitutions need to happen before - # _EscapeSpecialCharsWithinTagAttributes(), so that any *'s or _'s in the - # and tags get encoded. + # Called before the transformation process starts to setup parser + # states. # - # Clear the global hashes. If we don't clear these, you get conflicts - # from other articles when generating a page which contains more than - # one article (e.g. an index page that shows the N most recent - # articles): + # Clear global hashes. $this->urls = array(); $this->titles = array(); $this->html_hashes = array(); + $in_anchor = false; + } + + function teardown() { + # + # Called after the transformation process to clear any variable + # which may be taking up memory unnecessarly. + # + $this->urls = array(); + $this->titles = array(); + $this->html_hashes = array(); + } + + + function transform($text) { + # + # Main function. Performs some preprocessing on the input text + # and pass it through the document gamut. + # + $this->setup(); + # Remove UTF-8 BOM, if present. $text = preg_replace('{^\xEF\xBB\xBF}', '', $text); @@ -281,6 +296,8 @@ class Markdown_Parser { foreach ($this->document_gamut as $method => $priority) { $text = $this->$method($text); } + + $this->teardown(); return $text . "\n"; }