Skip to content
Browse files

Merge branch 'master' into extra

  • Loading branch information...
2 parents 0774f51 + 8e861d3 commit 48d95730f0930a7d96a6b58e0a455e8c3eed597f @michelf committed Apr 20, 2008
Showing with 28 additions and 11 deletions.
  1. +28 −11 markdown.php
View
39 markdown.php
@@ -250,23 +250,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);
@@ -293,6 +308,8 @@ function transform($text) {
foreach ($this->document_gamut as $method => $priority) {
$text = $this->$method($text);
}
+
+ $this->teardown();
return $text . "\n";
}

0 comments on commit 48d9573

Please sign in to comment.
Something went wrong with that request. Please try again.