content = json_decode($content, true); } public function execute() { return $this->handleParagraphs($this->content); } protected function handleParagraphs(array $paragraphs, $depth = 1) { $content = ''; foreach ($paragraphs as $paragraph) { $content = $content . str_repeat('#', $depth) . ' ' . (isset($paragraph['numbering']) ? $paragraph['numbering'] : '') . ' ' . $paragraph['content'] . "\n"; if ( array_key_exists('children', $paragraph) && $paragraph['children'] && is_array($paragraph['children']) ) { $childrenContent = $this->handleParagraphs($paragraph['children'], $depth + 1); $content = $content . $childrenContent; } } return $content; } }