| @@ 35-55 (lines=21) @@ | ||
| 32 | * @param string $source String or filename to convert |
|
| 33 | * @return string |
|
| 34 | */ |
|
| 35 | public function getTitle($source) |
|
| 36 | { |
|
| 37 | if ($this->isFile($source)) { |
|
| 38 | $source = file_get_contents($source); |
|
| 39 | } |
|
| 40 | ||
| 41 | // Try setext style first, then atx style |
|
| 42 | // @link https://github.com/michelf/php-markdown/blob/lib/Michelf/Markdown.php |
|
| 43 | // @see \Michelf\Markdown(Extra)::doHeaders() |
|
| 44 | $i = preg_match('/^(.+?)\s*\n(=+|-+)\s*\n/mx', $source, $ar); |
|
| 45 | if (0 == $i) { |
|
| 46 | $i = preg_match('/^\#{1,6}\s*(.+?)\s*\#*\n/mx', $source, $ar); |
|
| 47 | } |
|
| 48 | ||
| 49 | if (0 == $i) { |
|
| 50 | // Still not found |
|
| 51 | return null; |
|
| 52 | } else { |
|
| 53 | return $ar[1]; |
|
| 54 | } |
|
| 55 | } |
|
| 56 | } |
|
| 57 | ||
| @@ 144-161 (lines=18) @@ | ||
| 141 | * @param string $source String or filename to convert |
|
| 142 | * @return string |
|
| 143 | */ |
|
| 144 | public function getTitle($source) |
|
| 145 | { |
|
| 146 | if ($this->isFile($source)) { |
|
| 147 | $source = file_get_contents($source); |
|
| 148 | } |
|
| 149 | ||
| 150 | // Title adornment character |
|
| 151 | $tac = '(=+|-+|\\`+|\\:+|\\.+|\\\'+|\\"+|\\~+|\\^+|_+|\\*+|\\++|\\#+)'; |
|
| 152 | ||
| 153 | $i = preg_match("/$tac\\s*\\n(.+?)\\n\\1\\s*\\n/mx", $source, $ar); |
|
| 154 | ||
| 155 | if (0 == $i) { |
|
| 156 | // Not found |
|
| 157 | return null; |
|
| 158 | } else { |
|
| 159 | return $ar[2]; |
|
| 160 | } |
|
| 161 | } |
|
| 162 | ||
| 163 | ||
| 164 | ||