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

[2.x] Update the Markdown::render method to always use the smart Markdown service #1900

Merged
merged 2 commits into from
Jul 24, 2024
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
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ This serves two purposes:
- Reorganized and cleaned up the navigation and sidebar documentation for improved clarity.
- Moved the sidebar documentation to the documentation pages section for better organization.
- The build command now groups together all `InMemoryPage` instances under one progress bar group in https://github.com/hydephp/develop/pull/1897
- The `Markdown::render()` method will now always render Markdown using the custom HydePHP Markdown service (thus getting smart features like our Markdown processors) in https://github.com/hydephp/develop/pull/1900

### Deprecated
- for soon-to-be removed features.
Expand Down
14 changes: 3 additions & 11 deletions packages/framework/src/Markdown/Models/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Hyde\Markdown\Models;

use Hyde\Framework\Services\MarkdownService;
use Hyde\Markdown\MarkdownConverter;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\HtmlString;
Expand Down Expand Up @@ -84,20 +83,13 @@ public static function fromFile(string $path): static
/**
* Render a Markdown string into HTML.
*
* If a source model is provided, the Markdown will be converted using the dynamic MarkdownService,
* otherwise, the pre-configured singleton from the service container will be used instead.
* If a source page class is provided, that class will be used to configure
* the Hyde Markdown converter to enable features specific to that page.
*
* @return string $html
*/
public static function render(string $markdown, ?string $pageClass = null): string
{
if ($pageClass !== null) {
return (new MarkdownService($markdown, $pageClass))->parse();
} else {
/** @var MarkdownConverter $converter */
$converter = app(MarkdownConverter::class);

return (string) $converter->convert($markdown);
}
return (new MarkdownService($markdown, $pageClass))->parse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*/
class ColoredBlockquoteShortcodesTest extends UnitTestCase
{
protected static bool $needsKernel = true;
protected static bool $needsConfig = true;

public function testSignature()
{
$this->assertSame('>', ColoredBlockquotes::signature());
Expand Down
3 changes: 3 additions & 0 deletions packages/framework/tests/Unit/MarkdownFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*/
class MarkdownFacadeTest extends UnitTestCase
{
protected static bool $needsKernel = true;
protected static bool $needsConfig = true;

public function testRender(): void
{
$html = Markdown::render('# Hello World!');
Expand Down