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

Enable use of RenderedContentInterface and small fix #18

Merged
merged 5 commits into from
Sep 13, 2021

Conversation

mallardduck
Copy link
Contributor

hey @freekmurze - this change makes a quick fix for the 2.0 release related to extensions to help ensure things work properly. There were parts of the initial changes I made that were not covered by tests to catch the logic issue.

Quickfix

Make sure extensions can be given as class names (strings) or instances. So i've made adjustments to ensure extension load properly.

Specifically these lines would be affected:

$environment->addExtension(new $extension());

public function addExtension(ExtensionInterface $extension): self

New feature

This also adds a method that mimics the league convertToHtml method for users. Adding this method and covering it with tests was what caused me to encounter the error to begin with. Otherwise I would have opted to split them up.

This addition is important for users that want the FrontMatterExtension (or similar). Since these shouldn't return a string directly like existing methods do. So the new method returns a RenderedContentInterface object specific to the renderer. For instance, they can use any potential extension specific results. Like:

$result = app(\Spatie\LaravelMarkdown\MarkdownRenderer::class)->renderMarkdown($markdown);

// Grab the front matter:
if ($result instanceof RenderedContentWithFrontMatter) {
    $frontMatter = $result->getFrontMatter();
}

@freekmurze freekmurze merged commit 3dbf249 into spatie:main Sep 13, 2021
@freekmurze
Copy link
Member

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants