From 7b88cf4d4c9bb511e6c52dcee8b572f965f9f16b Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Thu, 7 Feb 2013 08:25:02 -0500 Subject: [PATCH 1/5] Added protection attributes. --- Michelf/Markdown.php | 276 +++++++++++++++++++++---------------------- Readme.md | 3 + 2 files changed, 141 insertions(+), 138 deletions(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 0fb3a04..0b6bcaa 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -32,11 +32,11 @@ class Markdown { ### Version ### - const MARKDOWNLIB_VERSION = "1.3-beta4"; + public const MARKDOWNLIB_VERSION = "1.3-beta4"; ### Simple Function Interface ### - static function defaultTransform($text) { + public static function defaultTransform($text) { # # Initialize the parser and return the result of its transform method. # This will work fine for derived classes too. @@ -59,34 +59,34 @@ class Markdown { ### Configuration Variables ### # Change to ">" for HTML output. - var $empty_element_suffix = " />"; - var $tab_width = 4; + public $empty_element_suffix = " />"; + public $tab_width = 4; # Change to `true` to disallow markup or entities. - var $no_markup = false; - var $no_entities = false; + public $no_markup = false; + public $no_entities = false; # Predefined urls and titles for reference links and images. - var $predef_urls = array(); - var $predef_titles = array(); + public $predef_urls = array(); + public $predef_titles = array(); ### Parser Implementation ### # Regex to match balanced [brackets]. # Needed to insert a maximum bracked depth while converting to PHP. - var $nested_brackets_depth = 6; - var $nested_brackets_re; + protected $nested_brackets_depth = 6; + protected $nested_brackets_re; - var $nested_url_parenthesis_depth = 4; - var $nested_url_parenthesis_re; + protected $nested_url_parenthesis_depth = 4; + protected $nested_url_parenthesis_re; # Table of hash values for escaped characters: - var $escape_chars = '\`*_{}[]()>#+-.!'; - var $escape_chars_re; + protected $escape_chars = '\`*_{}[]()>#+-.!'; + protected $escape_chars_re; - function __construct() { + public function __construct() { # # Constructor function. Initialize appropriate member variables. # @@ -111,15 +111,15 @@ class Markdown { # Internal hashes used during transformation. - var $urls = array(); - var $titles = array(); - var $html_hashes = array(); + protected $urls = array(); + protected $titles = array(); + protected $html_hashes = array(); # Status flag to avoid invalid nesting. - var $in_anchor = false; + protected $in_anchor = false; - function setup() { + protected function setup() { # # Called before the transformation process starts to setup parser # states. @@ -132,7 +132,7 @@ class Markdown { $in_anchor = false; } - function teardown() { + protected function teardown() { # # Called after the transformation process to clear any variable # which may be taking up memory unnecessarly. @@ -143,7 +143,7 @@ class Markdown { } - function transform($text) { + protected function transform($text) { # # Main function. Performs some preprocessing on the input text # and pass it through the document gamut. @@ -182,7 +182,7 @@ class Markdown { return $text . "\n"; } - var $document_gamut = array( + protected $document_gamut = array( # Strip link definitions, store in hashes. "stripLinkDefinitions" => 20, @@ -190,7 +190,7 @@ class Markdown { ); - function stripLinkDefinitions($text) { + protected function stripLinkDefinitions($text) { # # Strips link definitions from text, stores the URLs and titles in # hash references. @@ -224,7 +224,7 @@ class Markdown { $text); return $text; } - function _stripLinkDefinitions_callback($matches) { + protected function _stripLinkDefinitions_callback($matches) { $link_id = strtolower($matches[1]); $url = $matches[2] == '' ? $matches[3] : $matches[2]; $this->urls[$link_id] = $url; @@ -233,7 +233,7 @@ class Markdown { } - function hashHTMLBlocks($text) { + protected function hashHTMLBlocks($text) { if ($this->no_markup) return $text; $less_than_tab = $this->tab_width - 1; @@ -372,14 +372,14 @@ class Markdown { return $text; } - function _hashHTMLBlocks_callback($matches) { + protected function _hashHTMLBlocks_callback($matches) { $text = $matches[1]; $key = $this->hashBlock($text); return "\n\n$key\n\n"; } - function hashPart($text, $boundary = 'X') { + protected function hashPart($text, $boundary = 'X') { # # Called whenever a tag must be hashed when a function insert an atomic # element in the text stream. Passing $text to through this function gives @@ -402,7 +402,7 @@ class Markdown { } - function hashBlock($text) { + protected function hashBlock($text) { # # Shortcut function for hashPart with block-level boundaries. # @@ -410,7 +410,7 @@ class Markdown { } - var $block_gamut = array( + protected $block_gamut = array( # # These are all the transformations that form block-level # tags like paragraphs, headers, and list items. @@ -423,7 +423,7 @@ class Markdown { "doBlockQuotes" => 60, ); - function runBlockGamut($text) { + protected function runBlockGamut($text) { # # Run block gamut tranformations. # @@ -437,7 +437,7 @@ class Markdown { return $this->runBasicBlockGamut($text); } - function runBasicBlockGamut($text) { + protected function runBasicBlockGamut($text) { # # Run block gamut tranformations, without hashing HTML blocks. This is # useful when HTML blocks are known to be already hashed, like in the first @@ -454,7 +454,7 @@ class Markdown { } - function doHorizontalRules($text) { + protected function doHorizontalRules($text) { # Do Horizontal Rules: return preg_replace( '{ @@ -472,7 +472,7 @@ class Markdown { } - var $span_gamut = array( + protected $span_gamut = array( # # These are all the transformations that occur *within* block-level # tags like paragraphs, headers, and list items. @@ -496,7 +496,7 @@ class Markdown { "doHardBreaks" => 60, ); - function runSpanGamut($text) { + protected function runSpanGamut($text) { # # Run span gamut tranformations. # @@ -508,17 +508,17 @@ class Markdown { } - function doHardBreaks($text) { + protected function doHardBreaks($text) { # Do hard breaks: return preg_replace_callback('/ {2,}\n/', array(&$this, '_doHardBreaks_callback'), $text); } - function _doHardBreaks_callback($matches) { + protected function _doHardBreaks_callback($matches) { return $this->hashPart("empty_element_suffix\n"); } - function doAnchors($text) { + protected function doAnchors($text) { # # Turn Markdown link shortcuts into XHTML tags. # @@ -588,7 +588,7 @@ class Markdown { $this->in_anchor = false; return $text; } - function _doAnchors_reference_callback($matches) { + protected function _doAnchors_reference_callback($matches) { $whole_match = $matches[1]; $link_text = $matches[2]; $link_id =& $matches[3]; @@ -622,7 +622,7 @@ class Markdown { } return $result; } - function _doAnchors_inline_callback($matches) { + protected function _doAnchors_inline_callback($matches) { $whole_match = $matches[1]; $link_text = $this->runSpanGamut($matches[2]); $url = $matches[3] == '' ? $matches[4] : $matches[3]; @@ -643,7 +643,7 @@ class Markdown { } - function doImages($text) { + protected function doImages($text) { # # Turn Markdown image shortcuts into tags. # @@ -698,7 +698,7 @@ class Markdown { return $text; } - function _doImages_reference_callback($matches) { + protected function _doImages_reference_callback($matches) { $whole_match = $matches[1]; $alt_text = $matches[2]; $link_id = strtolower($matches[3]); @@ -726,7 +726,7 @@ class Markdown { return $result; } - function _doImages_inline_callback($matches) { + protected function _doImages_inline_callback($matches) { $whole_match = $matches[1]; $alt_text = $matches[2]; $url = $matches[3] == '' ? $matches[4] : $matches[3]; @@ -745,7 +745,7 @@ class Markdown { } - function doHeaders($text) { + protected function doHeaders($text) { # Setext-style headers: # Header 1 # ======== @@ -775,7 +775,7 @@ class Markdown { return $text; } - function _doHeaders_callback_setext($matches) { + protected function _doHeaders_callback_setext($matches) { # Terrible hack to check we haven't found an empty list item. if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) return $matches[0]; @@ -784,14 +784,14 @@ class Markdown { $block = "".$this->runSpanGamut($matches[1]).""; return "\n" . $this->hashBlock($block) . "\n\n"; } - function _doHeaders_callback_atx($matches) { + protected function _doHeaders_callback_atx($matches) { $level = strlen($matches[1]); $block = "".$this->runSpanGamut($matches[2]).""; return "\n" . $this->hashBlock($block) . "\n\n"; } - function doLists($text) { + protected function doLists($text) { # # Form HTML ordered (numbered) and unordered (bulleted) lists. # @@ -857,7 +857,7 @@ class Markdown { return $text; } - function _doLists_callback($matches) { + protected function _doLists_callback($matches) { # Re-usable patterns to match list item bullets and number markers: $marker_ul_re = '[*+-]'; $marker_ol_re = '\d+[\.]'; @@ -875,9 +875,9 @@ class Markdown { return "\n". $result ."\n\n"; } - var $list_level = 0; + protected $list_level = 0; - function processListItems($list_str, $marker_any_re) { + protected function processListItems($list_str, $marker_any_re) { # # Process the contents of a single ordered or unordered list, splitting it # into individual list items. @@ -923,7 +923,7 @@ class Markdown { $this->list_level--; return $list_str; } - function _processListItems_callback($matches) { + protected function _processListItems_callback($matches) { $item = $matches[4]; $leading_line =& $matches[1]; $leading_space =& $matches[2]; @@ -948,7 +948,7 @@ class Markdown { } - function doCodeBlocks($text) { + protected function doCodeBlocks($text) { # # Process Markdown `
` blocks.
 	#
@@ -966,7 +966,7 @@ class Markdown {
 
 		return $text;
 	}
-	function _doCodeBlocks_callback($matches) {
+	protected function _doCodeBlocks_callback($matches) {
 		$codeblock = $matches[1];
 
 		$codeblock = $this->outdent($codeblock);
@@ -980,7 +980,7 @@ class Markdown {
 	}
 
 
-	function makeCodeSpan($code) {
+	protected function makeCodeSpan($code) {
 	#
 	# Create a code span markup for $code. Called from handleSpanToken.
 	#
@@ -989,24 +989,24 @@ class Markdown {
 	}
 
 
-	var $em_relist = array(
+	protected $em_relist = array(
 		''  => '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(?
@@ -1166,7 +1166,7 @@ class Markdown {
 
 		return $text;
 	}
-	function _doBlockQuotes_callback($matches) {
+	protected function _doBlockQuotes_callback($matches) {
 		$bq = $matches[1];
 		# trim one level of quoting - trim whitespace-only lines
 		$bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq);
@@ -1180,14 +1180,14 @@ class Markdown {
 
 		return "\n". $this->hashBlock("
\n$bq\n
")."\n\n"; } - function _doBlockQuotes_callback2($matches) { + protected function _doBlockQuotes_callback2($matches) { $pre = $matches[1]; $pre = preg_replace('/^ /m', '', $pre); return $pre; } - function formParagraphs($text) { + protected function formParagraphs($text) { # # Params: # $text - string to process with html

tags @@ -1257,7 +1257,7 @@ class Markdown { } - function encodeAttribute($text) { + protected function encodeAttribute($text) { # # Encode text for a double-quoted HTML attribute. This function # is *not* suitable for attributes enclosed in single quotes. @@ -1268,7 +1268,7 @@ class Markdown { } - function encodeAmpsAndAngles($text) { + protected function encodeAmpsAndAngles($text) { # # Smart processing for ampersands and angle brackets that need to # be encoded. Valid character entities are left alone unless the @@ -1289,7 +1289,7 @@ class Markdown { } - function doAutoLinks($text) { + protected function doAutoLinks($text) { $text = preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i', array(&$this, '_doAutoLinks_url_callback'), $text); @@ -1316,19 +1316,19 @@ class Markdown { return $text; } - function _doAutoLinks_url_callback($matches) { + protected function _doAutoLinks_url_callback($matches) { $url = $this->encodeAttribute($matches[1]); $link = "$url"; return $this->hashPart($link); } - function _doAutoLinks_email_callback($matches) { + protected function _doAutoLinks_email_callback($matches) { $address = $matches[1]; $link = $this->encodeEmailAddress($address); return $this->hashPart($link); } - function encodeEmailAddress($addr) { + protected function encodeEmailAddress($addr) { # # Input: an email address, e.g. "foo@example.com" # @@ -1369,7 +1369,7 @@ class Markdown { } - function parseSpan($str) { + protected function parseSpan($str) { # # Take the string $str and parse it into tokens, hashing embeded HTML, # escaped characters and handling code spans. @@ -1429,7 +1429,7 @@ class Markdown { } - function handleSpanToken($token, &$str) { + protected function handleSpanToken($token, &$str) { # # Handle $token provided by parseSpan by determining its nature and # returning the corresponding value that should replace it. @@ -1453,7 +1453,7 @@ class Markdown { } - function outdent($text) { + protected function outdent($text) { # # Remove one level of line-leading tabs or spaces # @@ -1463,9 +1463,9 @@ class Markdown { # String length function for detab. `_initDetab` will create a function to # hanlde UTF-8 if the default function does not exist. - var $utf8_strlen = 'mb_strlen'; + protected $utf8_strlen = 'mb_strlen'; - function detab($text) { + protected function detab($text) { # # Replace tabs with the appropriate amount of space. # @@ -1478,7 +1478,7 @@ class Markdown { return $text; } - function _detab_callback($matches) { + protected function _detab_callback($matches) { $line = $matches[0]; $strlen = $this->utf8_strlen; # strlen function for UTF-8. @@ -1495,7 +1495,7 @@ class Markdown { } return $line; } - function _initDetab() { + protected function _initDetab() { # # Check for the availability of the function in the `utf8_strlen` property # (initially `mb_strlen`). If the function is not available, create a @@ -1509,14 +1509,14 @@ class Markdown { } - function unhash($text) { + protected function unhash($text) { # # Swap back in all the tags hashed by _HashHTMLBlocks. # return preg_replace_callback('/(.)\x1A[0-9]+\1/', array(&$this, '_unhash_callback'), $text); } - function _unhash_callback($matches) { + protected function _unhash_callback($matches) { return $this->html_hashes[$matches[0]]; } @@ -1540,34 +1540,34 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { ### Configuration Variables ### # Prefix for footnote ids. - var $fn_id_prefix = ""; + public $fn_id_prefix = ""; # Optional title attribute for footnote links and backlinks. - var $fn_link_title = ""; - var $fn_backlink_title = ""; + public $fn_link_title = ""; + public $fn_backlink_title = ""; # Optional class attribute for footnote links and backlinks. - var $fn_link_class = "footnote-ref"; - var $fn_backlink_class = "footnote-backref"; + public $fn_link_class = "footnote-ref"; + public $fn_backlink_class = "footnote-backref"; # Class name for table cell alignment (%% replaced left/center/right) # For instance: 'go-%%' becomes 'go-left' or 'go-right' or 'go-center' # If empty, the align attribute is used instead of a class name. - var $table_align_class_tmpl = ''; + public $table_align_class_tmpl = ''; # Optional class prefix for fenced code block. - var $code_class_prefix = ""; + public $code_class_prefix = ""; # Class attribute for code blocks goes on the `code` tag; # setting this to true will put attributes on the `pre` tag instead. - var $code_attr_on_pre = false; + public $code_attr_on_pre = false; # Predefined abbreviations. - var $predef_abbr = array(); + public $predef_abbr = array(); ### Parser Implementation ### - function __construct() { + public function __construct() { # # Constructor function. Initialize the parser object. # @@ -1598,18 +1598,18 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { # Extra variables used during extra transformations. - var $footnotes = array(); - var $footnotes_ordered = array(); - var $footnotes_ref_count = array(); - var $footnotes_numbers = array(); - var $abbr_desciptions = array(); - var $abbr_word_re = ''; + protected $footnotes = array(); + protected $footnotes_ordered = array(); + protected $footnotes_ref_count = array(); + protected $footnotes_numbers = array(); + protected $abbr_desciptions = array(); + protected $abbr_word_re = ''; # Give the current footnote number. - var $footnote_counter = 1; + protected $footnote_counter = 1; - function setup() { + protected function setup() { # # Setting up Extra-specific variables. # @@ -1631,7 +1631,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } } - function teardown() { + protected function teardown() { # # Clearing Extra-specific variables. # @@ -1649,11 +1649,11 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { ### Extra Attribute Parser ### # Expression to use to catch attributes (includes the braces) - var $id_class_attr_catch_re = '\{((?:[ ]*[#.][-_:a-zA-Z0-9]+){1,})[ ]*\}'; + protected $id_class_attr_catch_re = '\{((?:[ ]*[#.][-_:a-zA-Z0-9]+){1,})[ ]*\}'; # Expression to use when parsing in a context when no capture is desired - var $id_class_attr_nocatch_re = '\{(?:[ ]*[#.][-_:a-zA-Z0-9]+){1,}[ ]*\}'; + protected $id_class_attr_nocatch_re = '\{(?:[ ]*[#.][-_:a-zA-Z0-9]+){1,}[ ]*\}'; - function doExtraAttributes($tag_name, $attr) { + protected function doExtraAttributes($tag_name, $attr) { # # Parse attributes caught by the $this->id_class_attr_catch_re expression # and return the HTML-formatted list of attributes. @@ -1692,23 +1692,23 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { ### HTML Block Parser ### # Tags that are always treated as block tags: - var $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption'; + protected $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption'; # Tags treated as block tags only if the opening tag is alone on its line: - var $context_block_tags_re = 'script|noscript|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video'; + protected $context_block_tags_re = 'script|noscript|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video'; # Tags where markdown="1" default to span mode: - var $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address'; + protected $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address'; # Tags which must not have their contents modified, no matter where # they appear: - var $clean_tags_re = 'script|math|svg'; + protected $clean_tags_re = 'script|math|svg'; # Tags that do not need to be closed. - var $auto_close_tags_re = 'hr|img|param|source|track'; + protected $auto_close_tags_re = 'hr|img|param|source|track'; - function hashHTMLBlocks($text) { + protected function hashHTMLBlocks($text) { # # Hashify HTML Blocks and "clean tags". # @@ -1733,7 +1733,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { return $text; } - function _hashHTMLBlocks_inMarkdown($text, $indent = 0, + protected function _hashHTMLBlocks_inMarkdown($text, $indent = 0, $enclosing_tag_re = '', $span = false) { # @@ -1971,7 +1971,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { return array($parsed, $text); } - function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { + protected function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { # # Parse HTML, calling _HashHTMLBlocks_InMarkdown for block tags. # @@ -2146,7 +2146,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } - function hashClean($text) { + protected function hashClean($text) { # # Called whenever a tag must be hashed when a function inserts a "clean" tag # in $text, it passes through this function and is automaticaly escaped, @@ -2156,7 +2156,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } - function doHeaders($text) { + protected function doHeaders($text) { # # Redefined to add id and class attribute support. # @@ -2196,7 +2196,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { return $text; } - function _doHeaders_callback_setext($matches) { + protected function _doHeaders_callback_setext($matches) { if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) return $matches[0]; $level = $matches[3]{0} == '=' ? 1 : 2; @@ -2204,7 +2204,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { $block = "".$this->runSpanGamut($matches[1]).""; return "\n" . $this->hashBlock($block) . "\n\n"; } - function _doHeaders_callback_atx($matches) { + protected function _doHeaders_callback_atx($matches) { $level = strlen($matches[1]); $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[3]); $block = "".$this->runSpanGamut($matches[2]).""; @@ -2212,7 +2212,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } - function doTables($text) { + protected function doTables($text) { # # Form HTML tables. # @@ -2273,7 +2273,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { return $text; } - function _doTable_leadingPipe_callback($matches) { + protected function _doTable_leadingPipe_callback($matches) { $head = $matches[1]; $underline = $matches[2]; $content = $matches[3]; @@ -2283,7 +2283,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { return $this->_doTable_callback(array($matches[0], $head, $underline, $content)); } - function _doTable_makeAlignAttr($alignname) + protected function _doTable_makeAlignAttr($alignname) { if (empty($this->table_align_class_tmpl)) return " align=\"$alignname\""; @@ -2291,7 +2291,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { $classname = str_replace('%%', $alignname, $this->table_align_class_tmpl); return " class=\"$classname\""; } - function _doTable_callback($matches) { + protected function _doTable_callback($matches) { $head = $matches[1]; $underline = $matches[2]; $content = $matches[3]; @@ -2354,7 +2354,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } - function doDefLists($text) { + protected function doDefLists($text) { # # Form HTML definition lists. # @@ -2396,7 +2396,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { return $text; } - function _doDefLists_callback($matches) { + protected function _doDefLists_callback($matches) { # Re-usable patterns to match list item bullets and number markers: $list = $matches[1]; @@ -2408,7 +2408,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } - function processDefListItems($list_str) { + protected function processDefListItems($list_str) { # # Process the contents of a single definition list, splitting it # into individual term and definition list items. @@ -2451,7 +2451,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { return $list_str; } - function _processDefListItems_callback_dt($matches) { + protected function _processDefListItems_callback_dt($matches) { $terms = explode("\n", trim($matches[1])); $text = ''; foreach ($terms as $term) { @@ -2460,7 +2460,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } return $text . "\n"; } - function _processDefListItems_callback_dd($matches) { + protected function _processDefListItems_callback_dd($matches) { $leading_line = $matches[1]; $marker_space = $matches[2]; $def = $matches[3]; @@ -2480,7 +2480,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } - function doFencedCodeBlocks($text) { + protected function doFencedCodeBlocks($text) { # # Adding the fenced code block syntax to regular Markdown: # @@ -2519,7 +2519,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { return $text; } - function _doFencedCodeBlocks_callback($matches) { + protected function _doFencedCodeBlocks_callback($matches) { $classname =& $matches[2]; $attrs =& $matches[3]; $codeblock = $matches[4]; @@ -2540,7 +2540,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { return "\n\n".$this->hashBlock($codeblock)."\n\n"; } - function _doFencedCodeBlocks_newlines($matches) { + protected function _doFencedCodeBlocks_newlines($matches) { return str_repeat("empty_element_suffix", strlen($matches[0])); } @@ -2550,24 +2550,24 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { # Redefining emphasis markers so that emphasis by underscore does not # work in the middle of a word. # - var $em_relist = array( + protected $em_relist = array( '' => '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? tags @@ -2605,7 +2605,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { ### Footnotes - function stripFootnotes($text) { + protected function stripFootnotes($text) { # # Strips link definitions from text, stores the URLs and titles in # hash references. @@ -2632,14 +2632,14 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { $text); return $text; } - function _stripFootnotes_callback($matches) { + protected function _stripFootnotes_callback($matches) { $note_id = $this->fn_id_prefix . $matches[1]; $this->footnotes[$note_id] = $this->outdent($matches[2]); return ''; # String that will replace the block } - function doFootnotes($text) { + protected function doFootnotes($text) { # # Replace footnote references in $text [^id] with a special text-token # which will be replaced by the actual footnote marker in appendFootnotes. @@ -2651,7 +2651,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } - function appendFootnotes($text) { + protected function appendFootnotes($text) { # # Append footnote list to text. # @@ -2715,7 +2715,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } return $text; } - function _appendFootnotes_callback($matches) { + protected function _appendFootnotes_callback($matches) { $node_id = $this->fn_id_prefix . $matches[1]; # Create footnote marker only if it has a corresponding footnote *and* @@ -2759,7 +2759,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { ### Abbreviations ### - function stripAbbreviations($text) { + protected function stripAbbreviations($text) { # # Strips abbreviations from text, stores titles in hash references. # @@ -2774,7 +2774,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { $text); return $text; } - function _stripAbbreviations_callback($matches) { + protected function _stripAbbreviations_callback($matches) { $abbr_word = $matches[1]; $abbr_desc = $matches[2]; if ($this->abbr_word_re) @@ -2785,7 +2785,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } - function doAbbreviations($text) { + protected function doAbbreviations($text) { # # Find defined abbreviations in text and wrap them in elements. # @@ -2801,7 +2801,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } return $text; } - function _doAbbreviations_callback($matches) { + protected function _doAbbreviations_callback($matches) { $abbr = $matches[0]; if (isset($this->abbr_desciptions[$abbr])) { $desc = $this->abbr_desciptions[$abbr]; diff --git a/Readme.md b/Readme.md index dd1f664..aa15829 100644 --- a/Readme.md +++ b/Readme.md @@ -114,6 +114,9 @@ Version History Current Lib: +* Added `public` and `protected` protection attributes, plus a section about + what is "public API" and what isn't in the Readme. + * Changed HTML output for footnotes: now instead of adding `rel` and `rev` attributes, footnotes links have the class name `footnote-ref` and backlinks `footnote-backref`. (This change only affect Lib branch.) From d95ec6edf1ce26f663d06c65149daa3d928e3619 Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Thu, 7 Feb 2013 08:26:37 -0500 Subject: [PATCH 2/5] Added Public API and Versionning Policy to readme file. --- Readme.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Readme.md b/Readme.md index aa15829..7d12f27 100644 --- a/Readme.md +++ b/Readme.md @@ -95,6 +95,35 @@ To do this, you must set the `empty_element_suffix` variable of the parser object to ">". +Public API and Versionning Policy +--------------------------------- + +Version numbers are of the form *major*.*minor*.*patch*. + +The public API of PHP Markdown consist of the two parser classes `Markdown` +and `MarkdownExtra`, their constructors, the `transform` and `defaultTransform` +functions and their configuration variables. The public API is stable for +a given major version number. It might get additions when the minor version +number increments. + +**Protected members are not considered public API.** This is unconventionnal +and deserves an explanation. Incrementing the major version number every time +the underlying implementation of something changes is going to give nonsential +version numbers for the vast majority of people who just use the parser. +Protected members are meant to create parser subclasses that behave in +different ways. Very few people create parser subclasses. I don't want to +discourage it by making everything private, but at the same time I can't +guarenty any stable hook between versions if you use protected members. + +**Syntax changes** will increment the minor number for new features, and the +patch number for small corrections. A *new feature* is something that needs a +change in the syntax documentation. Note that since PHP Markdown Lib includes +two parsers, a syntax change for either of them will increment the minor +number. Also note that there is nothigng perfectly backward-compatible with the +Markdown syntax: all inputs are always valid, so new features always replace +something that was previously legal, although generally non-sensial to do. + + Bugs ---- From 46ca53917cb9f6588a71a1ff41db0ff93de47b56 Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Fri, 8 Feb 2013 08:42:37 -0500 Subject: [PATCH 3/5] Fixed readme to include information about beta 5. --- Readme.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 8a389b2..1fe63f0 100644 --- a/Readme.md +++ b/Readme.md @@ -150,8 +150,6 @@ Current Lib: attributes, footnotes links have the class name `footnote-ref` and backlinks `footnote-backref`. (This change only affect Lib branch.) -* Corrected namespace capitalization in composer package definition file. - Current Extra: @@ -170,6 +168,11 @@ Current Extra: [linkref]: url "optional title" {#id .class} +Lib 1.3-beta5 (3 Feb 2013): + +* Corrected namespace capitalization in composer package definition file. + + Lib 1.3-beta4 (21 Jan 2013): * Changed namespace name from michelf (lowercase) to Michelf (capitalized). From 7dd67edf6ce986162c3a367c93d900e2a6c32dc6 Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Fri, 8 Feb 2013 09:55:20 -0500 Subject: [PATCH 4/5] Added protected visibility attribute to a few new functions coming from the extra branch. --- Michelf/Markdown.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index b7e39a8..0394209 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -1724,7 +1724,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { $text); return $text; } - function _stripLinkDefinitions_callback($matches) { + protected function _stripLinkDefinitions_callback($matches) { $link_id = strtolower($matches[1]); $url = $matches[2] == '' ? $matches[3] : $matches[2]; $this->urls[$link_id] = $url; @@ -2272,7 +2272,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { $this->in_anchor = false; return $text; } - function _doAnchors_reference_callback($matches) { + protected function _doAnchors_reference_callback($matches) { $whole_match = $matches[1]; $link_text = $matches[2]; $link_id =& $matches[3]; @@ -2308,7 +2308,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } return $result; } - function _doAnchors_inline_callback($matches) { + protected function _doAnchors_inline_callback($matches) { $whole_match = $matches[1]; $link_text = $this->runSpanGamut($matches[2]); $url = $matches[3] == '' ? $matches[4] : $matches[3]; @@ -2332,7 +2332,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { } - function doImages($text) { + protected function doImages($text) { # # Turn Markdown image shortcuts into tags. # @@ -2388,7 +2388,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { return $text; } - function _doImages_reference_callback($matches) { + protected function _doImages_reference_callback($matches) { $whole_match = $matches[1]; $alt_text = $matches[2]; $link_id = strtolower($matches[3]); @@ -2418,7 +2418,7 @@ class _MarkdownExtra_TmpImpl extends \Michelf\Markdown { return $result; } - function _doImages_inline_callback($matches) { + protected function _doImages_inline_callback($matches) { $whole_match = $matches[1]; $alt_text = $matches[2]; $url = $matches[3] == '' ? $matches[4] : $matches[3]; From 756756595bf61dbcf14ca36ef3e5bee2edc14a7e Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Thu, 7 Mar 2013 08:28:44 -0500 Subject: [PATCH 5/5] Updates to readme file. --- Readme.md | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Readme.md b/Readme.md index 1fe63f0..6d05303 100644 --- a/Readme.md +++ b/Readme.md @@ -33,8 +33,8 @@ Full documentation of Markdown's syntax is available on John's Markdown page: -Installation and Requirement ----------------------------- +Requirement +----------- This library package requires PHP 5.3 or later. @@ -49,29 +49,35 @@ releases defaults to 1 000 000, which is usually fine. Usage ----- -You can use PHP Markdown easily in your PHP program. This library package -is meant to be used with autoloading, so putting the 'Michelf' folder -in your include path should be enough for this to work: +This library package is meant to be used with class autoloading. For autoloading +to work, your project needs have setup a PSR-0-compatible autoloader. See the +included Readme.php file for a minimal autoloader setup. (If you don't want to +use autoloading you can do a classic `require_once` to manually include the +files prior use instead.) + +With class autoloading in place, putting the 'Michelf' folder in your +include path should be enough for this to work: use \Michelf\Markdown; $my_html = Markdown::defaultTransform($my_text); -PHP Markdown Extra is also available the same way: +Markdown Extra syntax is also available the same way: use \Michelf\MarkdownExtra; $my_html = MarkdownExtra::defaultTransform($my_text); If you wish to use PHP Markdown with another text filter function -built to parse HTML, you should filter the text *after* the Markdown +built to parse HTML, you should filter the text *after* the `transform` function call. This is an example with [PHP SmartyPants][psp]: use \Michelf\Markdown, \Michelf\SmartyPants; $my_html = Markdown::defaultTransform($my_text); $my_html = SmartyPants::defaultTransform($my_html); -All these examples are using the static `markdown` function found inside the -parser class. If you want to customize the parser, you can also instantiate -it directly and change some configuration variables: +All these examples are using the static `defaultTransform` static function +found inside the parser class. If you want to customize the parser +configuration, you can also instantiate it directly and change some +configuration variables: use \Michelf\MarkdownExtra; $parser = new MarkdownExtra;