diff options
Diffstat (limited to 'plugins/jetpack/_inc/lib/markdown')
-rw-r--r-- | plugins/jetpack/_inc/lib/markdown/extra.php | 106 | ||||
-rw-r--r-- | plugins/jetpack/_inc/lib/markdown/gfm.php | 9 | ||||
-rw-r--r-- | plugins/jetpack/_inc/lib/markdown/test.php | 33 |
3 files changed, 58 insertions, 90 deletions
diff --git a/plugins/jetpack/_inc/lib/markdown/extra.php b/plugins/jetpack/_inc/lib/markdown/extra.php index 562acef8..4f52171f 100644 --- a/plugins/jetpack/_inc/lib/markdown/extra.php +++ b/plugins/jetpack/_inc/lib/markdown/extra.php @@ -72,34 +72,34 @@ class Markdown_Parser { ### Configuration Variables ### # Change to ">" for HTML output. - var $empty_element_suffix = MARKDOWN_EMPTY_ELEMENT_SUFFIX; - var $tab_width = MARKDOWN_TAB_WIDTH; + public $empty_element_suffix = MARKDOWN_EMPTY_ELEMENT_SUFFIX; + public $tab_width = MARKDOWN_TAB_WIDTH; # 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; + public $nested_brackets_depth = 6; + public $nested_brackets_re; - var $nested_url_parenthesis_depth = 4; - var $nested_url_parenthesis_re; + public $nested_url_parenthesis_depth = 4; + public $nested_url_parenthesis_re; # Table of hash values for escaped characters: - var $escape_chars = '\`*_{}[]()>#+-.!'; - var $escape_chars_re; + public $escape_chars = '\`*_{}[]()>#+-.!'; + public $escape_chars_re; - function Markdown_Parser() { + function __construct() { # # Constructor function. Initialize appropriate member variables. # @@ -124,12 +124,12 @@ class Markdown_Parser { # Internal hashes used during transformation. - var $urls = array(); - var $titles = array(); - var $html_hashes = array(); + public $urls = array(); + public $titles = array(); + public $html_hashes = array(); # Status flag to avoid invalid nesting. - var $in_anchor = false; + public $in_anchor = false; function setup() { @@ -195,7 +195,7 @@ class Markdown_Parser { return $text . "\n"; } - var $document_gamut = array( + public $document_gamut = array( # Strip link definitions, store in hashes. "stripLinkDefinitions" => 20, @@ -423,7 +423,7 @@ class Markdown_Parser { } - var $block_gamut = array( + public $block_gamut = array( # # These are all the transformations that form block-level # tags like paragraphs, headers, and list items. @@ -485,7 +485,7 @@ class Markdown_Parser { } - var $span_gamut = array( + public $span_gamut = array( # # These are all the transformations that occur *within* block-level # tags like paragraphs, headers, and list items. @@ -888,7 +888,7 @@ class Markdown_Parser { return "\n". $result ."\n\n"; } - var $list_level = 0; + public $list_level = 0; function processListItems($list_str, $marker_any_re) { # @@ -1002,22 +1002,22 @@ class Markdown_Parser { } - var $em_relist = array( + public $em_relist = array( '' => '(?:(?<!\*)\*(?!\*)|(?<!_)_(?!_))(?=\S|$)(?![\.,:;]\s)', '*' => '(?<=\S|^)(?<!\*)\*(?!\*)', '_' => '(?<=\S|^)(?<!_)_(?!_)', ); - var $strong_relist = array( + public $strong_relist = array( '' => '(?:(?<!\*)\*\*(?!\*)|(?<!_)__(?!_))(?=\S|$)(?![\.,:;]\s)', '**' => '(?<=\S|^)(?<!\*)\*\*(?!\*)', '__' => '(?<=\S|^)(?<!_)__(?!_)', ); - var $em_strong_relist = array( + public $em_strong_relist = array( '' => '(?:(?<!\*)\*\*\*(?!\*)|(?<!_)___(?!_))(?=\S|$)(?![\.,:;]\s)', '***' => '(?<=\S|^)(?<!\*)\*\*\*(?!\*)', '___' => '(?<=\S|^)(?<!_)___(?!_)', ); - var $em_strong_prepared_relist; + public $em_strong_prepared_relist; function prepareItalicsAndBold() { # @@ -1483,7 +1483,7 @@ class Markdown_Parser { # 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'; + public $utf8_strlen = 'mb_strlen'; function detab($text) { # @@ -1552,29 +1552,29 @@ class MarkdownExtra_Parser extends Markdown_Parser { ### 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 = MARKDOWN_FN_LINK_TITLE; - var $fn_backlink_title = MARKDOWN_FN_BACKLINK_TITLE; + public $fn_link_title = MARKDOWN_FN_LINK_TITLE; + public $fn_backlink_title = MARKDOWN_FN_BACKLINK_TITLE; # Optional class attribute for footnote links and backlinks. - var $fn_link_class = MARKDOWN_FN_LINK_CLASS; - var $fn_backlink_class = MARKDOWN_FN_BACKLINK_CLASS; + public $fn_link_class = MARKDOWN_FN_LINK_CLASS; + public $fn_backlink_class = MARKDOWN_FN_BACKLINK_CLASS; # Optional class prefix for fenced code block. - var $code_class_prefix = MARKDOWN_CODE_CLASS_PREFIX; + public $code_class_prefix = MARKDOWN_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 = MARKDOWN_CODE_ATTR_ON_PRE; + public $code_attr_on_pre = MARKDOWN_CODE_ATTR_ON_PRE; # Predefined abbreviations. - var $predef_abbr = array(); + public $predef_abbr = array(); ### Parser Implementation ### - function MarkdownExtra_Parser() { + function __construct() { # # Constructor function. Initialize the parser object. # @@ -1600,20 +1600,20 @@ class MarkdownExtra_Parser extends Markdown_Parser { "doAbbreviations" => 70, ); - parent::Markdown_Parser(); + parent::__construct(); } # 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 = ''; + public $footnotes = array(); + public $footnotes_ordered = array(); + public $footnotes_ref_count = array(); + public $footnotes_numbers = array(); + public $abbr_desciptions = array(); + public $abbr_word_re = ''; # Give the current footnote number. - var $footnote_counter = 1; + public $footnote_counter = 1; function setup() { @@ -1656,9 +1656,9 @@ class MarkdownExtra_Parser extends Markdown_Parser { ### Extra Attribute Parser ### # Expression to use to catch attributes (includes the braces) - var $id_class_attr_catch_re = '\{((?:[ ]*[#.][-_:a-zA-Z0-9]+){1,})[ ]*\}'; + public $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,}[ ]*\}'; + public $id_class_attr_nocatch_re = '\{(?:[ ]*[#.][-_:a-zA-Z0-9]+){1,}[ ]*\}'; function doExtraAttributes($tag_name, $attr) { # @@ -1744,20 +1744,20 @@ class MarkdownExtra_Parser extends Markdown_Parser { ### 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'; + public $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'; + public $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'; + public $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'; + public $clean_tags_re = 'script|math|svg'; # Tags that do not need to be closed. - var $auto_close_tags_re = 'hr|img|param|source|track'; + public $auto_close_tags_re = 'hr|img|param|source|track'; function hashHTMLBlocks($text) { @@ -2835,17 +2835,17 @@ class MarkdownExtra_Parser extends Markdown_Parser { # Redefining emphasis markers so that emphasis by underscore does not # work in the middle of a word. # - var $em_relist = array( + public $em_relist = array( '' => '(?:(?<!\*)\*(?!\*)|(?<![a-zA-Z0-9_])_(?!_))(?=\S|$)(?![\.,:;]\s)', '*' => '(?<=\S|^)(?<!\*)\*(?!\*)', '_' => '(?<=\S|^)(?<!_)_(?![a-zA-Z0-9_])', ); - var $strong_relist = array( + public $strong_relist = array( '' => '(?:(?<!\*)\*\*(?!\*)|(?<![a-zA-Z0-9_])__(?!_))(?=\S|$)(?![\.,:;]\s)', '**' => '(?<=\S|^)(?<!\*)\*\*(?!\*)', '__' => '(?<=\S|^)(?<!_)__(?![a-zA-Z0-9_])', ); - var $em_strong_relist = array( + public $em_strong_relist = array( '' => '(?:(?<!\*)\*\*\*(?!\*)|(?<![a-zA-Z0-9_])___(?!_))(?=\S|$)(?![\.,:;]\s)', '***' => '(?<=\S|^)(?<!\*)\*\*\*(?!\*)', '___' => '(?<=\S|^)(?<!_)___(?![a-zA-Z0-9_])', diff --git a/plugins/jetpack/_inc/lib/markdown/gfm.php b/plugins/jetpack/_inc/lib/markdown/gfm.php index 450742b2..6cd208af 100644 --- a/plugins/jetpack/_inc/lib/markdown/gfm.php +++ b/plugins/jetpack/_inc/lib/markdown/gfm.php @@ -64,7 +64,7 @@ class WPCom_GHF_Markdown_Parser extends MarkdownExtra_Parser { $this->preserve_latex = function_exists( 'latex_markup' ); $this->strip_paras = function_exists( 'wpautop' ); - parent::MarkdownExtra_Parser(); + parent::__construct(); } /** @@ -148,6 +148,7 @@ class WPCom_GHF_Markdown_Parser extends MarkdownExtra_Parser { public function do_codeblock_preserve( $matches ) { $block = stripslashes( $matches[3] ); $block = esc_html( $block ); + $block = str_replace( '\\', '\\\\', $block ); $open = $matches[1] . $matches[2] . "\n"; return $open . $block . $matches[4]; } @@ -264,10 +265,10 @@ class WPCom_GHF_Markdown_Parser extends MarkdownExtra_Parser { */ protected function get_shortcode_regex() { $pattern = get_shortcode_regex(); - + // don't match markdown link anchors that could be mistaken for shortcodes. - $pattern .= '(?!\()'; - + $pattern .= '(?!\()'; + return "/$pattern/s"; } diff --git a/plugins/jetpack/_inc/lib/markdown/test.php b/plugins/jetpack/_inc/lib/markdown/test.php deleted file mode 100644 index 8a0b08be..00000000 --- a/plugins/jetpack/_inc/lib/markdown/test.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -require 'extra.php'; -require 'gfm.php'; -$parser = new WPCom_GHF_Markdown_Parser; - -$text1 = <<<EOD -I am just back\slashing up a *storm* \*mofo*. - -EOD; - -$text = 'Just rockin in the *free* world - -```html -<html lang="en"> -</html> -``` -'; -#echo $text; -echo $parser->transform( $text ); -echo "\n\n\n"; -#echo $parser->hashBlock( '<pre>foobar</pre>' ); - - -$foo = <<<EOD -Here is a *list* with things: - -* some `code` is better than others -* **my** code is better than *yours* -* the best code is that which need not be written - -Selah. -EOD; |