标签:script end 字符 rip his object ext format obj
use Encore\Admin\Admin;
// 自动生成文章的摘录
$content = ‘content‘;
$excerpt = ‘excerpt‘;
Admin::script($this->getExcerptText($content, $excerpt));
$form->editormd($content, __(‘Content‘));
$form->textarea($excerpt, __(‘Excerpt‘))
->help(‘自动截取文章前500字‘)
->readonly();
这里使用了php的长字符串,如果你有需要,也可以自己使用js脚本文件
// 优化粘贴自动更新文章摘录
private function getExcerptText($content, $excerpt){
return <<<script
$(‘button[type="submit"]‘).click(()=>{
let text = editorMd{$content}.getPreviewedHTML().replace(/<[^>]*>/g,"");
if(text.length > 500){
$(‘textarea[name="{$excerpt}"]‘).val(text.substr(0,500)+‘...‘);
}
else{
$(‘textarea[name="{$excerpt}"]‘).val(text);
}
});
// 追加粘贴截图方法
inputPaste($(‘#{$content}‘), (url)=>{
// 获取光标的位置
let cursor = editorMd{$content}.getCursor();
editorMd{$content}.insertValue(‘![](‘ + url + ‘)‘);
// 设定光标的位置在图片的[]中
cursor.ch += 2;
editorMd{$content}.setCursor(cursor);
})
script;
}
说明:
editorMd{$content}
就是editormd实例化的当前的编辑器的类。体现在前端就是这样let config = Object.assign({id:‘content‘}, {"path":"\/vendor\/hxsen\/editormd\/editor.md\/lib\/","width":"100%","height":600,"emoji":true,"theme":"dark","previewTheme":"dark","editorTheme":"pastel-on-dark","imageUpload":true,"imageFormats":["jpg","jpeg","gif","png","bmp","webp"],"imageUploadURL":"\/admin\/editormd\/upload","codeFold":true,"taskList":true});
editorMdcontent = editormd(config);
editorMd{$content}.getPreviewedHTML()
是用来获取markdown解析好的html文本。replace(/<[^>]*>/g,"")
是对html文本进行文本提取。inputPaste
这个是我之前封装好的函数。用来监听当前元素的粘贴操作,并上传后台返回url。如果有需要点击查看[]
的中间,而不是在最后。laravel-admin使editormd支持粘贴截图并自动生成简介
标签:script end 字符 rip his object ext format obj
原文地址:https://www.cnblogs.com/hxsen/p/12688531.html