Laravel使用markdown详细

可我咋觉得你躺在这 我李云龙的半条命 也埋在这儿了……

使用SimpleMDE编辑器

页面上引入css和js文件

1
2
3
4
5
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">

<textarea name="profile" placeholder="这里请介绍你的专栏内容, 写作计划, 更新进度, 答疑情况等内容"></textarea>

<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>

初始化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<script>

var simplemde = new SimpleMDE({
spellChecker: false,
autosave: {
enabled: true,
delay: 5000,
unique_id: "article_content"
},
forceSync: true,
toolbar: [
"bold", "italic", "heading", "|", "quote", "code", "table",
"horizontal-rule", "unordered-list", "ordered-list", "|",
"link", "image", "|", "side-by-side", 'fullscreen', "|",
{
name: "guide",
action: function customFunction(editor) {
var win = window.open('https://github.com/riku/Markdown-Syntax-CN/blob/master/syntax.md', '_blank');
if (win) {
//Browser has allowed it to be opened
win.focus();
} else {
//Browser has blocked it
alert('Please allow popups for this website');
}
},
className: "fa fa-info-circle",
title: "Markdown 语法!"
},
{
name: "publish",
action: function customFunction(editor) {
$('.submit-btn').click();
},
className: "fa fa-paper-plane",
title: "发布文章"
}
],
});

</script>

页面输出解析markdown

安装扩展包

1
composer require erusev/parsedown

使用

1
2
3
$Parsedown = new Parsedown();

echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello <em>Parsedown</em>!</p>

https://simplemde.com/
https://packagist.org/packages/erusev/parsedown