0

非英语母语。

我的代码是什么:

File create.blade.php

<textarea> dirty markdown content </textarea> 
<preview> marked.js parsed html </preview>
<!-- this is a markdown editor, it can parse markdown to html using marked.js-->
<!-- then show in preview -->
<!-- something like stackoverflow editor does -->
<!-- when user edit done. post dirty markdown data to BlogController@create -->


File edit.blade.php

<textarea> parsed clean markdown content from backend </textarea>
<preview> clean parsed html</preview>

File BlogController.php

<?php
// get editor data from create.blade.php
// parse markdown content to prevent XSS
// save cleaned markdown content to DB
function create() {}

// get clean markdown data from DB
// return cleaned markdown content to edit.blade.php
function edit() {}

卡在台阶上

我被困在这一步:dirty markdown content<--在PHP中解析-->cleaned markdown content

我试过的

我试过:parsedown , commonmark HTMLPurifier 但我无法分离库。
比如commonmark,好像是 Dirty markdown content<--> Dirty AST tree<--->AST to HTML(with parse) 我认为步骤对AST to HTML(with parse)我来说很难分开作为AST tree<--> parsed AST tree<-->的一部分Cleaned markdown content

并且 HTMLPurifier 会解析所有的内容,包括script被 ``` 包围的标签:
之前

```html
some text
<script> some js code </script>
some text
```

使用 HTMLPurifier 后,返回

```html
some text
some text
```

脚本标签已经消失。

我的期望

一些可以解析dirty markdown content的库cleaned markdown content

ps:我使用的是laravel 7.*,marked.js,MySQL。
pps:感谢阅读,感谢您的任何建议。

更新

我期望的是:
用户编辑脏降价 ->clean dirty markdown -> cleaned markdown ->保存到数据库 -> 返回清理的降价内容 -> 用户编辑 -> ...

但也许还有另一种方法可以完成这项工作:
用户编辑脏降价 -> CommonMark -> cleaned HTML -> HTML to Markdown ->保存到数据库 -> 返回清理后的降价内容 -> 用户编辑 -> ...

4

0 回答 0