Skip to content

Commit

Permalink
Merge pull request #1900 from hydephp/simplify-markdown-rendering-helper
Browse files Browse the repository at this point in the history
[2.x] Update the `Markdown::render` method to always use the smart Markdown service
  • Loading branch information
caendesilva authored Jul 24, 2024
2 parents 612e3c3 + 2b6e40e commit 2df0527
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
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

0 comments on commit 2df0527

Please sign in to comment.