Making WordPress.org


Ignore:
Timestamp:
07/03/2020 03:11:38 AM (6 years ago)
Author:
dd32
Message:

Pinking shears, 10000

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/libs/michelf-php-markdown-1.6.0/Michelf/MarkdownExtra.php

    r2638 r10000  
    44#
    55# PHP Markdown Extra
    6 # Copyright (c) 2004-2015 Michel Fortin 
     6# Copyright (c) 2004-2015 Michel Fortin
    77# <https://michelf.ca/projects/php-markdown/>
    88#
    99# Original Markdown
    10 # Copyright (c) 2004-2006 John Gruber 
     10# Copyright (c) 2004-2006 John Gruber
    1111# <https://daringfireball.net/projects/markdown/>
    1212#
     
    5858        # Constructor function. Initialize the parser object.
    5959        #
    60                 # Add extra escapable characters before parent constructor 
     60                # Add extra escapable characters before parent constructor
    6161                # initialize the table.
    6262                $this->escape_chars .= ':|';
    6363               
    64                 # Insert extra document, block, and span transformations. 
     64                # Insert extra document, block, and span transformations.
    6565                # Parent constructor will do the sorting.
    6666                $this->document_gamut += array(
     
    237237        # Tags that are always treated as block tags:
    238238        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|figure';
    239                                                    
     239                                               
    240240        # Tags treated as block tags only if the opening tag is alone on its line:
    241241        protected $context_block_tags_re = 'script|noscript|style|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video';
     
    244244        protected $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address';
    245245       
    246         # Tags which must not have their contents modified, no matter where 
     246        # Tags which must not have their contents modified, no matter where
    247247        # they appear:
    248248        protected $clean_tags_re = 'script|style|math|svg';
     
    263263        #
    264264        # This works by calling _HashHTMLBlocks_InMarkdown, which then calls
    265         # _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1" 
     265        # _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1"
    266266        # attribute is found within a tag, _HashHTMLBlocks_InHTML calls back
    267267        #  _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag.
     
    283283        # Parse markdown text, calling _HashHTMLBlocks_InHTML for block tags.
    284284        #
    285         # *   $indent is the number of space to be ignored when checking for code 
    286         #     blocks. This is important because if we don't take the indent into 
     285        # *   $indent is the number of space to be ignored when checking for code
     286        #     blocks. This is important because if we don't take the indent into
    287287        #     account, something like this (which looks right) won't work as expected:
    288288        #
     
    296296        #     you apply the markdown="1" attribute.
    297297        #
    298         # *   If $enclosing_tag_re is not empty, stops at the first unmatched closing 
     298        # *   If $enclosing_tag_re is not empty, stops at the first unmatched closing
    299299        #     tag with that name. Nested tags supported.
    300300        #
    301         # *   If $span is true, text inside must treated as span. So any double 
    302         #     newline will be replaced by a single newline so that it does not create 
     301        # *   If $span is true, text inside must treated as span. So any double
     302        #     newline will be replaced by a single newline so that it does not create
    303303        #     paragraphs.
    304304        #
     
    309309                # Regex to check for the presense of newlines around a block tag.
    310310                $newline_before_re = '/(?:^\n?|\n\n)*$/';
    311                 $newline_after_re = 
     311                $newline_after_re =
    312312                        '{
    313313                                ^                                               # Start of text following the tag.
     
    382382                        # Split the text using the first $tag_match pattern found.
    383383                        # Text before  pattern will be first in the array, text after
    384                         # pattern will be at the end, and between will be any catches made 
     384                        # pattern will be at the end, and between will be any catches made
    385385                        # by the pattern.
    386386                        #
    387                         $parts = preg_split($block_tag_re, $text, 2, 
     387                        $parts = preg_split($block_tag_re, $text, 2,
    388388                                                                PREG_SPLIT_DELIM_CAPTURE);
    389389                       
    390                         # If in Markdown span mode, add a empty-string span-level hash 
     390                        # If in Markdown span mode, add a empty-string span-level hash
    391391                        # after each newline to prevent triggering any block element.
    392392                        if ($span) {
     
    418418                                $fence_re = $capture[2]; # use captured fence in re
    419419                                if (preg_match('{^(?>.*\n)*?[ ]{'.($fence_indent).'}'.$fence_re.'[ ]*(?:\n|$)}', $text,
    420                                         $matches)) 
     420                                        $matches))
    421421                                {
    422422                                        # End marker found: pass text unchanged until marker.
     
    433433                        #
    434434                        else if ($tag{0} == "\n" || $tag{0} == " ") {
    435                                 # Indented code block: pass it unchanged, will be handled 
     435                                # Indented code block: pass it unchanged, will be handled
    436436                                # later.
    437437                                $parsed .= $tag;
     
    458458                        #
    459459                        # Check for: Opening Block level tag or
    460                         #            Opening Context Block tag (like ins and del) 
     460                        #            Opening Context Block tag (like ins and del)
    461461                        #               used as a block tag (tag is alone on it's line).
    462462                        #
     
    468468                        {
    469469                                # Need to parse tag and following text using the HTML parser.
    470                                 list($block_text, $text) = 
     470                                list($block_text, $text) =
    471471                                        $this->_hashHTMLBlocks_inHTML($tag . $text, "hashBlock", true);
    472472                               
     
    483483                                # Need to parse tag and following text using the HTML parser.
    484484                                # (don't check for markdown attribute)
    485                                 list($block_text, $text) = 
     485                                list($block_text, $text) =
    486486                                        $this->_hashHTMLBlocks_inHTML($tag . $text, "hashClean", false);
    487487                               
     
    591591                        # Split the text using the first $tag_match pattern found.
    592592                        # Text before  pattern will be first in the array, text after
    593                         # pattern will be at the end, and between will be any catches made 
     593                        # pattern will be at the end, and between will be any catches made
    594594                        # by the pattern.
    595595                        #
     
    600600                                # End of $text reached with unbalenced tag(s).
    601601                                # In that case, we return original text unchanged and pass the
    602                                 # first character as filtered to prevent an infinite loop in the 
     602                                # first character as filtered to prevent an infinite loop in the
    603603                                # parent function.
    604604                                #
     
    633633                                # Check for `markdown="1"` attribute and handle it.
    634634                                #
    635                                 if ($md_attr && 
     635                                if ($md_attr &&
    636636                                        preg_match($markdown_attr_re, $tag, $attr_m) &&
    637637                                        preg_match('/^1|block|span$/', $attr_m[2] . $attr_m[3]))
     
    664664                                        # Parse the content using the HTML-in-Markdown parser.
    665665                                        list ($block_text, $text)
    666                                                 = $this->_hashHTMLBlocks_inMarkdown($text, $indent, 
     666                                                = $this->_hashHTMLBlocks_inMarkdown($text, $indent,
    667667                                                        $tag_name_re, $span_mode);
    668668                                       
    669669                                        # Outdent markdown text.
    670670                                        if ($indent > 0) {
    671                                                 $block_text = preg_replace("/^[ ]{1,$indent}/m", "", 
     671                                                $block_text = preg_replace("/^[ ]{1,$indent}/m", "",
    672672                                                                                                        $block_text);
    673673                                        }
     
    697697        #
    698698        # Called whenever a tag must be hashed when a function inserts a "clean" tag
    699         # in $text, it passes through this function and is automaticaly escaped, 
     699        # in $text, it passes through this function and is automaticaly escaped,
    700700        # blocking invalid nested overlap.
    701701        #
     
    861861
    862862                        )
    863                         }xs', 
     863                        }xs',
    864864                        array($this, '_doImages_reference_callback'), $text);
    865865
     
    954954                #         Header 1  {#header1}
    955955                #         ========
    956                 # 
     956                #
    957957                #         Header 2  {#header2 .class1 .class2}
    958958                #         --------
     
    11111111                }
    11121112               
    1113                 # Parsing span elements, including code spans, character escapes, 
     1113                # Parsing span elements, including code spans, character escapes,
    11141114                # and inline HTML tags, so that pipes inside those gets ignored.
    11151115                $head           = $this->parseSpan($head);
     
    11321132                $text .= "<tbody>\n";
    11331133                foreach ($rows as $row) {
    1134                         # Parsing span elements, including code spans, character escapes, 
     1134                        # Parsing span elements, including code spans, character escapes,
    11351135                        # and inline HTML tags, so that pipes inside those gets ignored.
    11361136                        $row = $this->parseSpan($row);
     
    12251225                                (?> \S.* \n)+?                          # actual term (not whitespace).
    12261226                        )                       
    1227                         (?=\n?[ ]{0,3}:[ ])                             # lookahead for following line feed 
     1227                        (?=\n?[ ]{0,3}:[ ])                             # lookahead for following line feed
    12281228                                                                                        #   with a definition mark.
    12291229                        }xm',
     
    13471347        }
    13481348        protected function _doFencedCodeBlocks_newlines($matches) {
    1349                 return str_repeat("<br$this->empty_element_suffix", 
     1349                return str_repeat("<br$this->empty_element_suffix",
    13501350                        strlen($matches[0]));
    13511351        }
     
    13991399                }
    14001400               
    1401                 # Join grafs in one text, then unhash HTML tags. 
     1401                # Join grafs in one text, then unhash HTML tags.
    14021402                $text = implode("\n\n", $grafs);
    14031403               
     
    14271427                                        .+                              # actual text
    14281428                                |
    1429                                         \n                              # newlines but 
     1429                                        \n                              # newlines but
    14301430                                        (?!\[.+?\][ ]?:\s)# negative lookahead for footnote or link definition marker.
    1431                                         (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed 
     1431                                        (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed
    14321432                                                                        # by non-indented content
    14331433                                )*
     
    14471447        protected function doFootnotes($text) {
    14481448        #
    1449         # Replace footnote references in $text [^id] with a special text-token 
     1449        # Replace footnote references in $text [^id] with a special text-token
    14501450        # which will be replaced by the actual footnote marker in appendFootnotes.
    14511451        #
     
    14611461        # Append footnote list to text.
    14621462        #
    1463                 $text = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', 
     1463                $text = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}',
    14641464                        array($this, '_appendFootnotes_callback'), $text);
    14651465       
     
    14941494                                $footnote .= "\n"; # Need to append newline before parsing.
    14951495                                $footnote = $this->runBlockGamut("$footnote\n");                               
    1496                                 $footnote = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', 
     1496                                $footnote = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}',
    14971497                                        array($this, '_appendFootnotes_callback'), $footnote);
    14981498                               
     
    15981598        #
    15991599                if ($this->abbr_word_re) {
    1600                         // cannot use the /x modifier because abbr_word_re may 
     1600                        // cannot use the /x modifier because abbr_word_re may
    16011601                        // contain significant spaces:
    16021602                        $text = preg_replace_callback('{'.
     
    16041604                                '(?:'.$this->abbr_word_re.')'.
    16051605                                '(?![\w\x1A])'.
    1606                                 '}', 
     1606                                '}',
    16071607                                array($this, '_doAbbreviations_callback'), $text);
    16081608                }
Note: See TracChangeset for help on using the changeset viewer.