| @@ 219-252 (lines=34) @@ | ||
| 216 | ); |
|
| 217 | ||
| 218 | ||
| 219 | function stripLinkDefinitions($text) { |
|
| 220 | # |
|
| 221 | # Strips link definitions from text, stores the URLs and titles in |
|
| 222 | # hash references. |
|
| 223 | # |
|
| 224 | $less_than_tab = $this->tab_width - 1; |
|
| 225 | ||
| 226 | # Link defs are in the form: ^[id]: url "optional title" |
|
| 227 | $text = preg_replace_callback('{ |
|
| 228 | ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 |
|
| 229 | [ ]* |
|
| 230 | \n? # maybe *one* newline |
|
| 231 | [ ]* |
|
| 232 | (?: |
|
| 233 | <(.+?)> # url = $2 |
|
| 234 | | |
|
| 235 | (\S+?) # url = $3 |
|
| 236 | ) |
|
| 237 | [ ]* |
|
| 238 | \n? # maybe one newline |
|
| 239 | [ ]* |
|
| 240 | (?: |
|
| 241 | (?<=\s) # lookbehind for whitespace |
|
| 242 | ["(] |
|
| 243 | (.*?) # title = $4 |
|
| 244 | [")] |
|
| 245 | [ ]* |
|
| 246 | )? # title is optional |
|
| 247 | (?:\n+|\Z) |
|
| 248 | }xm', |
|
| 249 | array(&$this, '_stripLinkDefinitions_callback'), |
|
| 250 | $text); |
|
| 251 | return $text; |
|
| 252 | } |
|
| 253 | function _stripLinkDefinitions_callback($matches) { |
|
| 254 | $link_id = strtolower($matches[1]); |
|
| 255 | $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| @@ 1712-1746 (lines=35) @@ | ||
| 1709 | } |
|
| 1710 | ||
| 1711 | ||
| 1712 | function stripLinkDefinitions($text) { |
|
| 1713 | # |
|
| 1714 | # Strips link definitions from text, stores the URLs and titles in |
|
| 1715 | # hash references. |
|
| 1716 | # |
|
| 1717 | $less_than_tab = $this->tab_width - 1; |
|
| 1718 | ||
| 1719 | # Link defs are in the form: ^[id]: url "optional title" |
|
| 1720 | $text = preg_replace_callback('{ |
|
| 1721 | ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 |
|
| 1722 | [ ]* |
|
| 1723 | \n? # maybe *one* newline |
|
| 1724 | [ ]* |
|
| 1725 | (?: |
|
| 1726 | <(.+?)> # url = $2 |
|
| 1727 | | |
|
| 1728 | (\S+?) # url = $3 |
|
| 1729 | ) |
|
| 1730 | [ ]* |
|
| 1731 | \n? # maybe one newline |
|
| 1732 | [ ]* |
|
| 1733 | (?: |
|
| 1734 | (?<=\s) # lookbehind for whitespace |
|
| 1735 | ["(] |
|
| 1736 | (.*?) # title = $4 |
|
| 1737 | [")] |
|
| 1738 | [ ]* |
|
| 1739 | )? # title is optional |
|
| 1740 | (?:[ ]* '.$this->id_class_attr_catch_re.' )? # $5 = extra id & class attr |
|
| 1741 | (?:\n+|\Z) |
|
| 1742 | }xm', |
|
| 1743 | array(&$this, '_stripLinkDefinitions_callback'), |
|
| 1744 | $text); |
|
| 1745 | return $text; |
|
| 1746 | } |
|
| 1747 | function _stripLinkDefinitions_callback($matches) { |
|
| 1748 | $link_id = strtolower($matches[1]); |
|
| 1749 | $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| @@ 2781-2819 (lines=39) @@ | ||
| 2778 | } |
|
| 2779 | ||
| 2780 | ||
| 2781 | function doFencedCodeBlocks($text) { |
|
| 2782 | # |
|
| 2783 | # Adding the fenced code block syntax to regular Markdown: |
|
| 2784 | # |
|
| 2785 | # ~~~ |
|
| 2786 | # Code block |
|
| 2787 | # ~~~ |
|
| 2788 | # |
|
| 2789 | $less_than_tab = $this->tab_width; |
|
| 2790 | ||
| 2791 | $text = preg_replace_callback('{ |
|
| 2792 | (?:\n|\A) |
|
| 2793 | # 1: Opening marker |
|
| 2794 | ( |
|
| 2795 | (?:~{3,}|`{3,}) # 3 or more tildes/backticks. |
|
| 2796 | ) |
|
| 2797 | [ ]* |
|
| 2798 | (?: |
|
| 2799 | \.?([-_:a-zA-Z0-9]+) # 2: standalone class name |
|
| 2800 | | |
|
| 2801 | '.$this->id_class_attr_catch_re.' # 3: Extra attributes |
|
| 2802 | )? |
|
| 2803 | [ ]* \n # Whitespace and newline following marker. |
|
| 2804 | ||
| 2805 | # 4: Content |
|
| 2806 | ( |
|
| 2807 | (?> |
|
| 2808 | (?!\1 [ ]* \n) # Not a closing marker. |
|
| 2809 | .*\n+ |
|
| 2810 | )+ |
|
| 2811 | ) |
|
| 2812 | ||
| 2813 | # Closing marker. |
|
| 2814 | \1 [ ]* (?= \n ) |
|
| 2815 | }xm', |
|
| 2816 | array(&$this, '_doFencedCodeBlocks_callback'), $text); |
|
| 2817 | ||
| 2818 | return $text; |
|
| 2819 | } |
|
| 2820 | function _doFencedCodeBlocks_callback($matches) { |
|
| 2821 | $classname =& $matches[2]; |
|
| 2822 | $attrs =& $matches[3]; |
|
| @@ 2906-2932 (lines=27) @@ | ||
| 2903 | ||
| 2904 | ### Footnotes |
|
| 2905 | ||
| 2906 | function stripFootnotes($text) { |
|
| 2907 | # |
|
| 2908 | # Strips link definitions from text, stores the URLs and titles in |
|
| 2909 | # hash references. |
|
| 2910 | # |
|
| 2911 | $less_than_tab = $this->tab_width - 1; |
|
| 2912 | ||
| 2913 | # Link defs are in the form: [^id]: url "optional title" |
|
| 2914 | $text = preg_replace_callback('{ |
|
| 2915 | ^[ ]{0,'.$less_than_tab.'}\[\^(.+?)\][ ]?: # note_id = $1 |
|
| 2916 | [ ]* |
|
| 2917 | \n? # maybe *one* newline |
|
| 2918 | ( # text = $2 (no blank lines allowed) |
|
| 2919 | (?: |
|
| 2920 | .+ # actual text |
|
| 2921 | | |
|
| 2922 | \n # newlines but |
|
| 2923 | (?!\[\^.+?\]:\s)# negative lookahead for footnote marker. |
|
| 2924 | (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed |
|
| 2925 | # by non-indented content |
|
| 2926 | )* |
|
| 2927 | ) |
|
| 2928 | }xm', |
|
| 2929 | array(&$this, '_stripFootnotes_callback'), |
|
| 2930 | $text); |
|
| 2931 | return $text; |
|
| 2932 | } |
|
| 2933 | function _stripFootnotes_callback($matches) { |
|
| 2934 | $note_id = $this->fn_id_prefix . $matches[1]; |
|
| 2935 | $this->footnotes[$note_id] = $this->outdent($matches[2]); |
|
| @@ 3061-3075 (lines=15) @@ | ||
| 3058 | ||
| 3059 | ### Abbreviations ### |
|
| 3060 | ||
| 3061 | function stripAbbreviations($text) { |
|
| 3062 | # |
|
| 3063 | # Strips abbreviations from text, stores titles in hash references. |
|
| 3064 | # |
|
| 3065 | $less_than_tab = $this->tab_width - 1; |
|
| 3066 | ||
| 3067 | # Link defs are in the form: [id]*: url "optional title" |
|
| 3068 | $text = preg_replace_callback('{ |
|
| 3069 | ^[ ]{0,'.$less_than_tab.'}\*\[(.+?)\][ ]?: # abbr_id = $1 |
|
| 3070 | (.*) # text = $2 (no blank lines allowed) |
|
| 3071 | }xm', |
|
| 3072 | array(&$this, '_stripAbbreviations_callback'), |
|
| 3073 | $text); |
|
| 3074 | return $text; |
|
| 3075 | } |
|
| 3076 | function _stripAbbreviations_callback($matches) { |
|
| 3077 | $abbr_word = $matches[1]; |
|
| 3078 | $abbr_desc = $matches[2]; |
|