| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace Dcat\Admin\Widgets;
- use Dcat\Admin\Support\Helper;
- use Illuminate\Contracts\Support\Renderable;
- use Illuminate\Support\Str;
- class Markdown extends Widget
- {
- protected $view = 'admin::widgets.markdown';
- /**
- * @var string|Renderable
- */
- protected $content;
- /**
- * 配置.
- *
- * @var array
- */
- protected $options = [
- 'htmlDecode' => 'style,script,iframe',
- 'emoji' => true,
- 'taskList' => true,
- 'tex' => true,
- 'flowChart' => true,
- 'sequenceDiagram' => true,
- ];
- public function __construct($markdown = '')
- {
- $this->content($markdown);
- }
- /**
- * @param string|Renderable $markdown
- *
- * @return $this
- */
- public function content($markdown)
- {
- $this->content = &$markdown;
- return $this;
- }
- protected function renderContent()
- {
- return Helper::render($this->content);
- }
- public function render()
- {
- $id = 'mkd-'.Str::random(8);
- $this->defaultHtmlAttribute('id', $id);
- $this->with([
- 'id' => $id,
- 'content' => $this->renderContent(),
- ]);
- return parent::render();
- }
- }
|