| @@ 359-392 (lines=34) @@ | ||
| 356 | ); |
|
| 357 | ||
| 358 | ||
| 359 | function stripLinkDefinitions($text) { |
|
| 360 | # |
|
| 361 | # Strips link definitions from text, stores the URLs and titles in |
|
| 362 | # hash references. |
|
| 363 | # |
|
| 364 | $less_than_tab = $this->tab_width - 1; |
|
| 365 | ||
| 366 | # Link defs are in the form: ^[id]: url "optional title" |
|
| 367 | $text = preg_replace_callback('{ |
|
| 368 | ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 |
|
| 369 | [ ]* |
|
| 370 | \n? # maybe *one* newline |
|
| 371 | [ ]* |
|
| 372 | (?: |
|
| 373 | <(.+?)> # url = $2 |
|
| 374 | | |
|
| 375 | (\S+?) # url = $3 |
|
| 376 | ) |
|
| 377 | [ ]* |
|
| 378 | \n? # maybe one newline |
|
| 379 | [ ]* |
|
| 380 | (?: |
|
| 381 | (?<=\s) # lookbehind for whitespace |
|
| 382 | ["(] |
|
| 383 | (.*?) # title = $4 |
|
| 384 | [")] |
|
| 385 | [ ]* |
|
| 386 | )? # title is optional |
|
| 387 | (?:\n+|\Z) |
|
| 388 | }xm', |
|
| 389 | array(&$this, '_stripLinkDefinitions_callback'), |
|
| 390 | $text); |
|
| 391 | return $text; |
|
| 392 | } |
|
| 393 | function _stripLinkDefinitions_callback($matches) { |
|
| 394 | $link_id = strtolower($matches[1]); |
|
| 395 | $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| @@ 1852-1886 (lines=35) @@ | ||
| 1849 | } |
|
| 1850 | ||
| 1851 | ||
| 1852 | function stripLinkDefinitions($text) { |
|
| 1853 | # |
|
| 1854 | # Strips link definitions from text, stores the URLs and titles in |
|
| 1855 | # hash references. |
|
| 1856 | # |
|
| 1857 | $less_than_tab = $this->tab_width - 1; |
|
| 1858 | ||
| 1859 | # Link defs are in the form: ^[id]: url "optional title" |
|
| 1860 | $text = preg_replace_callback('{ |
|
| 1861 | ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 |
|
| 1862 | [ ]* |
|
| 1863 | \n? # maybe *one* newline |
|
| 1864 | [ ]* |
|
| 1865 | (?: |
|
| 1866 | <(.+?)> # url = $2 |
|
| 1867 | | |
|
| 1868 | (\S+?) # url = $3 |
|
| 1869 | ) |
|
| 1870 | [ ]* |
|
| 1871 | \n? # maybe one newline |
|
| 1872 | [ ]* |
|
| 1873 | (?: |
|
| 1874 | (?<=\s) # lookbehind for whitespace |
|
| 1875 | ["(] |
|
| 1876 | (.*?) # title = $4 |
|
| 1877 | [")] |
|
| 1878 | [ ]* |
|
| 1879 | )? # title is optional |
|
| 1880 | (?:[ ]* '.$this->id_class_attr_catch_re.' )? # $5 = extra id & class attr |
|
| 1881 | (?:\n+|\Z) |
|
| 1882 | }xm', |
|
| 1883 | array(&$this, '_stripLinkDefinitions_callback'), |
|
| 1884 | $text); |
|
| 1885 | return $text; |
|
| 1886 | } |
|
| 1887 | function _stripLinkDefinitions_callback($matches) { |
|
| 1888 | $link_id = strtolower($matches[1]); |
|
| 1889 | $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| @@ 2921-2959 (lines=39) @@ | ||
| 2918 | } |
|
| 2919 | ||
| 2920 | ||
| 2921 | function doFencedCodeBlocks($text) { |
|
| 2922 | # |
|
| 2923 | # Adding the fenced code block syntax to regular Markdown: |
|
| 2924 | # |
|
| 2925 | # ~~~ |
|
| 2926 | # Code block |
|
| 2927 | # ~~~ |
|
| 2928 | # |
|
| 2929 | $less_than_tab = $this->tab_width; |
|
| 2930 | ||
| 2931 | $text = preg_replace_callback('{ |
|
| 2932 | (?:\n|\A) |
|
| 2933 | # 1: Opening marker |
|
| 2934 | ( |
|
| 2935 | (?:~{3,}|`{3,}) # 3 or more tildes/backticks. |
|
| 2936 | ) |
|
| 2937 | [ ]* |
|
| 2938 | (?: |
|
| 2939 | \.?([-_:a-zA-Z0-9]+) # 2: standalone class name |
|
| 2940 | | |
|
| 2941 | '.$this->id_class_attr_catch_re.' # 3: Extra attributes |
|
| 2942 | )? |
|
| 2943 | [ ]* \n # Whitespace and newline following marker. |
|
| 2944 | ||
| 2945 | # 4: Content |
|
| 2946 | ( |
|
| 2947 | (?> |
|
| 2948 | (?!\1 [ ]* \n) # Not a closing marker. |
|
| 2949 | .*\n+ |
|
| 2950 | )+ |
|
| 2951 | ) |
|
| 2952 | ||
| 2953 | # Closing marker. |
|
| 2954 | \1 [ ]* (?= \n ) |
|
| 2955 | }xm', |
|
| 2956 | array(&$this, '_doFencedCodeBlocks_callback'), $text); |
|
| 2957 | ||
| 2958 | return $text; |
|
| 2959 | } |
|
| 2960 | function _doFencedCodeBlocks_callback($matches) { |
|
| 2961 | $classname =& $matches[2]; |
|
| 2962 | $attrs =& $matches[3]; |
|
| @@ 3046-3072 (lines=27) @@ | ||
| 3043 | ||
| 3044 | ### Footnotes |
|
| 3045 | ||
| 3046 | function stripFootnotes($text) { |
|
| 3047 | # |
|
| 3048 | # Strips link definitions from text, stores the URLs and titles in |
|
| 3049 | # hash references. |
|
| 3050 | # |
|
| 3051 | $less_than_tab = $this->tab_width - 1; |
|
| 3052 | ||
| 3053 | # Link defs are in the form: [^id]: url "optional title" |
|
| 3054 | $text = preg_replace_callback('{ |
|
| 3055 | ^[ ]{0,'.$less_than_tab.'}\[\^(.+?)\][ ]?: # note_id = $1 |
|
| 3056 | [ ]* |
|
| 3057 | \n? # maybe *one* newline |
|
| 3058 | ( # text = $2 (no blank lines allowed) |
|
| 3059 | (?: |
|
| 3060 | .+ # actual text |
|
| 3061 | | |
|
| 3062 | \n # newlines but |
|
| 3063 | (?!\[\^.+?\]:\s)# negative lookahead for footnote marker. |
|
| 3064 | (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed |
|
| 3065 | # by non-indented content |
|
| 3066 | )* |
|
| 3067 | ) |
|
| 3068 | }xm', |
|
| 3069 | array(&$this, '_stripFootnotes_callback'), |
|
| 3070 | $text); |
|
| 3071 | return $text; |
|
| 3072 | } |
|
| 3073 | function _stripFootnotes_callback($matches) { |
|
| 3074 | $note_id = $this->fn_id_prefix . $matches[1]; |
|
| 3075 | $this->footnotes[$note_id] = $this->outdent($matches[2]); |
|
| @@ 3201-3215 (lines=15) @@ | ||
| 3198 | ||
| 3199 | ### Abbreviations ### |
|
| 3200 | ||
| 3201 | function stripAbbreviations($text) { |
|
| 3202 | # |
|
| 3203 | # Strips abbreviations from text, stores titles in hash references. |
|
| 3204 | # |
|
| 3205 | $less_than_tab = $this->tab_width - 1; |
|
| 3206 | ||
| 3207 | # Link defs are in the form: [id]*: url "optional title" |
|
| 3208 | $text = preg_replace_callback('{ |
|
| 3209 | ^[ ]{0,'.$less_than_tab.'}\*\[(.+?)\][ ]?: # abbr_id = $1 |
|
| 3210 | (.*) # text = $2 (no blank lines allowed) |
|
| 3211 | }xm', |
|
| 3212 | array(&$this, '_stripAbbreviations_callback'), |
|
| 3213 | $text); |
|
| 3214 | return $text; |
|
| 3215 | } |
|
| 3216 | function _stripAbbreviations_callback($matches) { |
|
| 3217 | $abbr_word = $matches[1]; |
|
| 3218 | $abbr_desc = $matches[2]; |
|