From 794afca0a1c2ffdb5f9c309355719e748440b6c9 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Wed, 9 Mar 2016 13:25:07 -0500 Subject: [PATCH] Inject markdown content as variable instead of rendering flat into Blade template --- src/Handlers/MarkdownHandler.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Handlers/MarkdownHandler.php b/src/Handlers/MarkdownHandler.php index d48c2070..e3146abc 100644 --- a/src/Handlers/MarkdownHandler.php +++ b/src/Handlers/MarkdownHandler.php @@ -37,9 +37,11 @@ public function render($file, $data) { $document = $this->parseFile($file); - $bladeContent = $this->compileToBlade($document); + $data = array_merge($data, $document->getYAML(), [ + '__jigsawMarkdownContent' => $document->getContent() + ]); - $data = array_merge($data, $document->getYAML()); + $bladeContent = $this->compileToBlade($document->getYAML()['extends'], $document->getYAML()['section']); return $this->temporaryFilesystem->put($bladeContent, function ($path) use ($data) { return $this->viewFactory->file($path, $data)->render(); @@ -51,14 +53,12 @@ private function parseFile($file) return $this->parser->parse($file->getContents()); } - private function compileToBlade($document) + private function compileToBlade($extends, $section) { - $frontmatter = $document->getYAML(); - return collect([ - sprintf("@extends('%s')", $frontmatter['extends']), - sprintf("@section('%s')", $frontmatter['section']), - $document->getContent(), + sprintf("@extends('%s')", $extends), + sprintf("@section('%s')", $section), + '{!! $__jigsawMarkdownContent !!}', '@endsection', ])->implode("\n"); }