| @@ 315-331 (lines=17) @@ | ||
| 312 | * |
|
| 313 | * @return array with the formatted text and the front matter. |
|
| 314 | */ |
|
| 315 | public function jsonFrontMatter($text) |
|
| 316 | { |
|
| 317 | list($text, $frontmatter) = $this->extractFrontMatter($text, "{{{\n", "}}}\n"); |
|
| 318 | ||
| 319 | if (!empty($frontmatter)) { |
|
| 320 | $frontmatter = json_decode($frontmatter, true); |
|
| 321 | ||
| 322 | if (is_null($frontmatter)) { |
|
| 323 | throw new Exception("Failed parsing JSON frontmatter."); |
|
| 324 | } |
|
| 325 | } |
|
| 326 | ||
| 327 | return [ |
|
| 328 | "text" => $text, |
|
| 329 | "frontmatter" => $frontmatter |
|
| 330 | ]; |
|
| 331 | } |
|
| 332 | ||
| 333 | ||
| 334 | ||
| @@ 342-358 (lines=17) @@ | ||
| 339 | * |
|
| 340 | * @return array with the formatted text and the front matter. |
|
| 341 | */ |
|
| 342 | public function yamlFrontMatter($text) |
|
| 343 | { |
|
| 344 | list($text, $frontmatter) = $this->extractFrontMatter($text, "---\n", "...\n"); |
|
| 345 | ||
| 346 | if (function_exists("yaml_parse") && !empty($frontmatter)) { |
|
| 347 | $frontmatter = yaml_parse("---\n$frontmatter...\n"); |
|
| 348 | ||
| 349 | if ($frontmatter === false) { |
|
| 350 | throw new Exception("Failed parsing YAML frontmatter."); |
|
| 351 | } |
|
| 352 | } |
|
| 353 | ||
| 354 | return [ |
|
| 355 | "text" => $text, |
|
| 356 | "frontmatter" => $frontmatter |
|
| 357 | ]; |
|
| 358 | } |
|
| 359 | ||
| 360 | ||
| 361 | ||