Skip to content

Commit

Permalink
Merge pull request #670 from hydephp/add-hyde-markdown-helper
Browse files Browse the repository at this point in the history
Add a Hyde::markdown() helper
  • Loading branch information
caendesilva authored Nov 17, 2022
2 parents ec3c401 + 1b40229 commit d6cbfcd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Hyde\Foundation\Concerns;

use Hyde\Markdown\Models\Markdown;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;

/**
Expand All @@ -23,4 +25,9 @@ public function makeTitle(string $slug): string
Str::headline($slug)
));
}

public function markdown(string $text): HtmlString
{
return new HtmlString(Markdown::render($text));
}
}
2 changes: 2 additions & 0 deletions packages/framework/src/Hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Hyde\Pages\Concerns\HydePage;
use Hyde\Support\Models\Route;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\HtmlString;

/**
* General facade for Hyde services.
Expand All @@ -36,6 +37,7 @@
* @method static string image(string $name, bool $preferQualifiedUrl = false)
* @method static string url(string $path = '')
* @method static string makeTitle(string $slug)
* @method static HtmlString markdown(string $text)
* @method static string currentPage()
* @method static string getBasePath()
* @method static string getSourceRoot()
Expand Down
6 changes: 6 additions & 0 deletions packages/framework/tests/Feature/HydeKernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Hyde\Testing\TestCase;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\View;
use Illuminate\Support\HtmlString;

/**
* This test class runs high-level tests on the HydeKernel class,
Expand Down Expand Up @@ -90,6 +91,11 @@ public function test_make_title_helper_returns_title_from_page_slug()
$this->assertEquals('Foo Bar', Hyde::makeTitle('foo-bar'));
}

public function test_markdown_helper_converts_markdown_to_html()
{
$this->assertEquals(new HtmlString("<p>foo</p>\n"), Hyde::markdown('foo'));
}

public function test_format_html_path_helper_formats_path_according_to_config_rules()
{
Config::set('site.pretty_urls', false);
Expand Down

0 comments on commit d6cbfcd

Please sign in to comment.