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