Skip to content

Instantly share code, notes, and snippets.

@daronspence
Created April 29, 2022 15:23
Show Gist options
  • Save daronspence/09c7a5712fd59ce7cedd7543a4aafa6b to your computer and use it in GitHub Desktop.
Save daronspence/09c7a5712fd59ce7cedd7543a4aafa6b to your computer and use it in GitHub Desktop.
Stringable Markdown with Iframe Support
<?php
// within AppServiceProvider::boot() or a similar entry point
Stringable::macro('markdownWithIframes', function ($config = []) {
$config['disallowed_raw_html'] = [
'disallowed_tags' => ['title', 'textarea', 'style', 'xmp', 'noembed', 'noframes', 'script', 'plaintext'],
];
$environment = new Environment($config);
$environment->addExtension(new CommonMarkCoreExtension());
$environment->addExtension(new AutolinkExtension());
$environment->addExtension(new DisallowedRawHtmlExtension());
$environment->addExtension(new StrikethroughExtension());
$environment->addExtension(new TableExtension());
$environment->addExtension(new TaskListExtension());
$converter = new MarkdownConverter($environment);
return new static($converter->convert($this->value));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment