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