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

[11.x] Add Support for Extensions in Str::markdown Method #51907

Merged
merged 3 commits into from
Jun 25, 2024

Conversation

tnylea
Copy link
Contributor

@tnylea tnylea commented Jun 25, 2024

Hey Taylor and team 👋 Hope you guys are doing well!

I wanted to submit a simple PR that allows anyone using the Str::markdown(...) method to add some CommonMark Extensions as a third parameter. Here is a quick example of how you could use this in a controller:

public function parseMarkdownFromFile($file_location){

    $markdown_contents = File::get($file_location);
    
    $html = Str::markdown($markdown_contents, [], [
        new AttributesExtension(),
        new TaskListExtension(),
    ]);

    return $html;

}

Here's a quick 60 second video of this in action 👍 Sound on 🔉

common-mark-extensions.mp4

I didn't see any tests associated with the Str::markdown() method, but if there are some you would like me to update, let me know 😉 I'm open to making any changes if there's another way you want to see this implemented.

Really appreciate it. Talk to you soon!

@taylorotwell taylorotwell merged commit df7f734 into laravel:11.x Jun 25, 2024
28 checks passed
@driesvints driesvints changed the title Add Support for Extensions in Str::markdown Method [11.x] Add Support for Extensions in Str::markdown Method Jun 27, 2024
Comment on lines +645 to +649
$environment = $converter->getEnvironment();

foreach ($extensions as $extension) {
$environment->addExtension($extension);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The environment is only needed when $extensions !== []. Wouldn't it make sense, to wrap this in an if?

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.

3 participants