| @@ 324-340 (lines=17) @@ | ||
| 321 | * |
|
| 322 | * @return array with the formatted text and the front matter. |
|
| 323 | */ |
|
| 324 | public function jsonFrontMatter($text) |
|
| 325 | { |
|
| 326 | list($text, $frontmatter) = $this->extractFrontMatter($text, "{{{\n", "}}}\n"); |
|
| 327 | ||
| 328 | if (!empty($frontmatter)) { |
|
| 329 | $frontmatter = json_decode($frontmatter, true); |
|
| 330 | ||
| 331 | if (is_null($frontmatter)) { |
|
| 332 | throw new Exception("Failed parsing JSON frontmatter."); |
|
| 333 | } |
|
| 334 | } |
|
| 335 | ||
| 336 | return [ |
|
| 337 | "text" => $text, |
|
| 338 | "frontmatter" => $frontmatter |
|
| 339 | ]; |
|
| 340 | } |
|
| 341 | ||
| 342 | ||
| 343 | ||
| @@ 351-367 (lines=17) @@ | ||
| 348 | * |
|
| 349 | * @return array with the formatted text and the front matter. |
|
| 350 | */ |
|
| 351 | public function yamlFrontMatter($text) |
|
| 352 | { |
|
| 353 | list($text, $frontmatter) = $this->extractFrontMatter($text, "---\n", "...\n"); |
|
| 354 | ||
| 355 | if (function_exists("yaml_parse") && !empty($frontmatter)) { |
|
| 356 | $frontmatter = yaml_parse("---\n$frontmatter...\n"); |
|
| 357 | ||
| 358 | if ($frontmatter === false) { |
|
| 359 | throw new Exception("Failed parsing YAML frontmatter."); |
|
| 360 | } |
|
| 361 | } |
|
| 362 | ||
| 363 | return [ |
|
| 364 | "text" => $text, |
|
| 365 | "frontmatter" => $frontmatter |
|
| 366 | ]; |
|
| 367 | } |
|
| 368 | ||
| 369 | ||
| 370 | ||