Permalink
Browse files

Added setup and teardown methods for easy overriding.

  • Loading branch information...
michelf committed Apr 21, 2008
1 parent 83c4ffe commit 8e861d340bae10f215c4aa15b363484bd33c2d3b
Showing with 28 additions and 11 deletions.
  1. +28 −11 markdown.php
View
@@ -238,23 +238,38 @@ function 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 <a>
- # and <img> 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 @@ function transform($text) {
foreach ($this->document_gamut as $method => $priority) {
$text = $this->$method($text);
}
+
+ $this->teardown();
return $text . "\n";
}

0 comments on commit 8e861d3

Please sign in to comment.