<commit_before><?php 

# 
# 
# Parsedown
# http://parsedown.org
# 
# (c) <NAME> 
# http://erusev.com
# 
# For the full license information, please view the LICENSE file that was 
# distributed with this source code.
# 
# 

class Parsedown
{
	# 
	# Multiton (http://en.wikipedia.org/wiki/Multiton_pattern) 
	# 
	
	static function instance($name = 'default')
	{
		if (isset(self::$instances[$name]))
			return self::$instances[$name];
		
		$instance = new Parsedown();
		
		self::$instances[$name] = $instance;
		
		return $instance;
	}
	
	private static $instances = array();
	
	# 
	# Fields 
	# 
	
	private $reference_map = array();
	private $escape_sequence_map = array();
	
	# 
	# Public Methods 
	# 
	
	function parse($text)
	{	
		# Removes UTF-8 BOM and marker characters.
		$text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text);
		
		# Removes \r characters.
		$text = str_replace("\r\n", "\n", $text);
		$text = str_replace("\r", "\n", $text);
		
		# Replaces tabs with spaces.
		$text = str_replace("\t", '    ', $text);
		
		# Encodes escape sequences.
		
		if (strpos($text, '\\') !== FALSE)
		{
			$escape_sequences = array('\\\\', '\`', '\*', '\_', '\{', '\}', '\[', '\]', '\(', '\)', '\>', '\#', '\+', '\-', '\.', '\!');
			
			foreach ($escape_sequences as $index => $escape_sequence)
			{
				if (strpos($text, $escape_sequence) !== FALSE)
				{
					$code = "\x1A".'\\'.$index;
					
					$text = str_replace($escape_sequence, $code, $text);
					
					$this->escape_sequence_map[$code] = $escape_sequence;
				}
			}
		}
		
		# Extracts link references.
		
		if (preg_match_all('/^[ ]{0,3}\[(.+)\][ ]?:[ ]*\n?[ ]*(.+)$/m', $text, $matches, PREG_SET_ORDER))
		{
			foreach ($matches as $matches)
			{
				$this->reference_map[strtolower($matches[1])] = $matches[2];
				
				$text = str_replace($matches[0], '', $text);
			}
		}
		
		# ~ 
		
		$text = trim($text, "\n");
		$text = preg_replace('/\n\s*\n/', "\n\n", $text);
		
		$text = $this->parse_lines($text);
		
		# Decodes escape sequences (leaves out backslashes).
		
		foreach ($this->escape_sequence_map as $code => $escape_sequence)
		{
			$text = str_replace($code, $escape_sequence[1], $text);
		}
		
		$text = rtrim($text, "\n");
		
		return $text;
	}
	
	# 
	# Private Methods 
	# 
	
	private function parse_lines($text, $context = null)
	{
		$lines = explode("\n", $text);
		$lines []= NULL;
		
		$line_count = count($lines);
		
		$markup = '';
		
		foreach ($lines as $index => $line)
		{
			# Quick Line 
			
			if (isset($line) and $line !== '' and $line[0] >= 'A')
			{
				$quick_line = $line;
				
				unset($line);
			}
			
			# Setext Heading (-)
			
			if (isset($line) and $line !== '' and isset($paragraph) and preg_match('/^[-]+[ ]*$/', $line))
			{
				$setext_heading_text = $this->parse_inline_elements($paragraph);
				
				$markup .= '<h2>'.$setext_heading_text.'</h2>'."\n";
				
				unset($paragraph, $line);<commit_msg>NULL » null<commit_after><?php 

# 
# 
# Parsedown
# http://parsedown.org
# 
# (c) <NAME> 
# http://erusev.com
# 
# For the full license information, please view the LICENSE file that was 
# distributed with this source code.
# 
# 

class Parsedown
{
	# 
	# Multiton (http://en.wikipedia.org/wiki/Multiton_pattern) 
	# 
	
	static function instance($name = 'default')
	{
		if (isset(self::$instances[$name]))
			return self::$instances[$name];
		
		$instance = new Parsedown();
		
		self::$instances[$name] = $instance;
		
		return $instance;
	}
	
	private static $instances = array();
	
	# 
	# Fields 
	# 
	
	private $reference_map = array();
	private $escape_sequence_map = array();
	
	# 
	# Public Methods 
	# 
	
	function parse($text)
	{	
		# Removes UTF-8 BOM and marker characters.
		$text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text);
		
		# Removes \r characters.
		$text = str_replace("\r\n", "\n", $text);
		$text = str_replace("\r", "\n", $text);
		
		# Replaces tabs with spaces.
		$text = str_replace("\t", '    ', $text);
		
		# Encodes escape sequences.
		
		if (strpos($text, '\\') !== FALSE)
		{
			$escape_sequences = array('\\\\', '\`', '\*', '\_', '\{', '\}', '\[', '\]', '\(', '\)', '\>', '\#', '\+', '\-', '\.', '\!');
			
			foreach ($escape_sequences as $index => $escape_sequence)
			{
				if (strpos($text, $escape_sequence) !== FALSE)
				{
					$code = "\x1A".'\\'.$index;
					
					$text = str_replace($escape_sequence, $code, $text);
					
					$this->escape_sequence_map[$code] = $escape_sequence;
				}
			}
		}
		
		# Extracts link references.
		
		if (preg_match_all('/^[ ]{0,3}\[(.+)\][ ]?:[ ]*\n?[ ]*(.+)$/m', $text, $matches, PREG_SET_ORDER))
		{
			foreach ($matches as $matches)
			{
				$this->reference_map[strtolower($matches[1])] = $matches[2];
				
				$text = str_replace($matches[0], '', $text);
			}
		}
		
		# ~ 
		
		$text = trim($text, "\n");
		$text = preg_replace('/\n\s*\n/', "\n\n", $text);
		
		$text = $this->parse_lines($text);
		
		# Decodes escape sequences (leaves out backslashes).
		
		foreach ($this->escape_sequence_map as $code => $escape_sequence)
		{
			$text = str_replace($code, $escape_sequence[1], $text);
		}
		
		$text = rtrim($text, "\n");
		
		return $text;
	}
	
	# 
	# Private Methods 
	# 
	
	private function parse_lines($text, $context = null)
	{
		$lines = explode("\n", $text);
		$lines []= null;
		
		$line_count = count($lines);
		
		$markup = '';
		
		foreach ($lines as $index => $line)
		{
			# Quick Line 
			
			if (isset($line) and $line !== '' and $line[0] >= 'A')
			{
				$quick_line = $line;
				
				unset($line);
			}
			
			# Setext Heading (-)
			
			if (isset($line) and $line !== '' and isset($paragraph) and preg_match('/^[-]+[ ]*$/', $line))
			{
				$setext_heading_text = $this->parse_inline_elements($paragraph);
				
				$markup .= '<h2>'.$setext_heading_text.'</h2>'."\n";
				
				unset($paragraph, $line);
{'fraction_non_alphanumeric': 0.22018505825908155, 'fraction_numerical': 0.00411240575736806, 'mean_word_length': 2.8225278323510152, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4958195', 'n_tokens_mistral': 2601, 'n_tokens_neox': 2132, 'n_words': 415}