Returning markdown in Page

I am a plugin newb, but got most of the way there. I am trying to build a simple webservice pluggin that fetches github release content and displays in on a page. In general the pluggin should query the GITHUB API, return JSON (Which includes Markdown text), Convert JSON to an array, process the array using a foreach, send the results to the page. The Markdown should be processed when displayed to the user.

I am using the https://learn.getgrav.org/cookbook/plugin-recipes#output-some-php-code-result-in-a-twig-template code as a starter. Everything is working as expected, but my only challenge is the output is not being formatted using markdown. Below is my code:

<?php
namespace Grav\Plugin;

class ExampleTwigExtension extends \Twig_Extension
{
    public function getName()
    {
        return 'ExampleTwigExtension';
    }
    public function getFunctions()
    {
       return [
           new \Twig_SimpleFunction('example', [$this, 'exampleFunction'])
        ];
    }
	

public function exampleFunction()
{
	$text = "";
	
	//Set Variables
	$token = "TOKEN";
	$url = "GITHUB URL";

	$decode_token = base64_decode($token);
	
	//Init Curl
	$ch = curl_init();
	$timeout = 5;
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_FAILONERROR,true);
	curl_setopt($ch, CURLOPT_USERPWD, "$decode_token");
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
	curl_setopt($ch, CURLOPT_HEADER, 0);

	//Set as variable to be re-used.
	$data = curl_exec($ch);

	$returned_content = $data;

	//Convert JSON data to an ARRAY so that it can be parsed.
	$releases = json_decode($returned_content, true);

	
	if(curl_error($ch)) {
		
		$text.= '<h3>There has been an error!</h3>';
		$text.= '<p>
				I am unable to get release information.  Please contact <a href="mailto:address@domain.com?subject=NISP Release Error: ' .curl_error($ch).' ">CIS Governance</a> for more assistance
			   </p>';
		$text.= 'Ref:'. curl_error($ch);
		
		}else{
		
			foreach ($releases as $release) {
				$text.= '<div class="page-header">';
				$text.= '<h2>';
				$text.= $release['name'];
				$text.= '</h2>';
				$text.= '</div>';		
				$text.= '<div class="list-group">';
				$text.= "\n\n". $release['body'];
				$text.= '</div>';
				
			}
		
	}
	
	 // Return the Processed Text <<<< THIS IS Where I suspect I am doing something wrong...
	 return $text;
	
    }
}

I found a work-around as I couldn’t figure out how to use the markdown class to return already processed markdown. I ended up using an alternative markdown processor. (https://github.com/michelf/php-markdown) See the new code below:

<?php
namespace Grav\Plugin;

use \Michelf\Markdown;

class ChangelogExtension extends \Twig_Extension
{
	public function getName(){
		return 'ChangelogExtension';
	}

	public function getFunctions(){
		return [
			new \Twig_SimpleFunction('changelog', [$this, 'changelogFunction'])
		];
	}


	public function changelogFunction(){

		//Include Markdown Parser
		require_once 'vendor/php-markdown-1.7.0/Michelf/Markdown.inc.php';	

		//Set or Initialize Variables
		$text = "";
		$token = "TOKEN";
		$url = "GITHUB URL";
		$timeout = 5;
		$decode_token = base64_decode($token);

		//Init Curl
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_FAILONERROR,true);
		curl_setopt($ch, CURLOPT_USERPWD, "$decode_token");
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
		curl_setopt($ch, CURLOPT_HEADER, 0);

		//Set as variable to be re-used.
		$data = curl_exec($ch);

		$returned_content = $data;

		//Convert JSON data to an ARRAY so that it can be parsed.
		$releases = json_decode($returned_content, true);


		if(curl_error($ch)) {

			$text.= '<h3>There has been an error!</h3>';
			$text.= '<p>
					I am unable to get release information.  Please contact <a href="address@domain.com?subject=DC Tool Release Error: ' .curl_error($ch).' ">CONTACT</a> for more assistance
				   </p>';
			$text.= 'Ref:'. curl_error($ch);

			}else{

				foreach ($releases as $release) {
					$text.= '<div class="page-header">';
					$text.= '<h2>';
					$text.= $release['name'];
					$text.= '</h2>';
					$text.= '</div>';		
					$text.= '<div class="list-group">';
					$text.= "\n";
					$text.= $release['body'];
					$text.= '</div>';

				}

		}

		 // Process the MarkDown
		 $mdtext = Markdown::defaultTransform($text);

		 //Return the converted content
		 return $mdtext;
		}
}