Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Hyde::markdown() helper #670

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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