如何让 MarkDown 不解析某些内容?

2016-11-26 09:00:24 +08:00
 hilaolu

我需要在我的 ghost 博客文章中插入一段 js

<script>function call(){var xhr=new XMLHttpRequest();
xhr.onreadystatechange=function(){if(xhr.readyState===4){if(xhr.status>=200&&xhr.status<300||xhr.status===304){var a=JSON.parse(xhr.responseText);
var b=new DPlayer({screenshot:false,video:{url:a.durl[0].url}})}else{console.log("Request was unsuccessful:"+xhr.status)}}};
xhr.open("get","https://api.prprpr.me/dplayer/video/bilibili?aid=706",true);xhr.send(null);}
</script>

MarkDown 会将===……===解析成<mark>=……=</mark>(高亮标记)

这样这段 js 就报 Uncaught SyntaxError: Unexpected token

我想到 markdown 解析在前端完成,于是在数据库里将实际内容改过来,便可以正常运行。

这样搞得我好累,各种 google 又看不懂老外的英文。听说 v2 大神多,便来求助:如何让 MarkDown 不解析某些内容?

7716 次点击
所在节点    Markdown
10 条回复
lazyyz
2016-11-26 09:02:02 +08:00
code 标记
misaka19000
2016-11-26 09:18:08 +08:00
把===换成==
meathill
2016-11-26 10:22:26 +08:00


```
代码块
```

或者

<pre>
代码块
</pre>

或者

<code>代码块</code>
crs0910
2016-11-26 10:33:45 +08:00
正确做法: <script type="text/javascript">
crs0910
2016-11-26 10:35:00 +08:00
遇到这种普遍性比较高的问题去 github 项目 issue 里面搜索一般能够很快解决

https://github.com/TryGhost/Ghost/issues/5587
SpicyCat
2016-11-26 11:00:28 +08:00
楼主你是要展示这段 JS 代码还是要运行?
hilaolu
2016-11-26 11:15:04 +08:00
@crs0910 谢答,只有你答到点上了。英文实在不好。
feather12315
2016-11-26 11:18:09 +08:00
通常,{%raw%} {%endraw%} 搞定一切
JiaFeiX
2016-11-26 21:20:59 +08:00
~~~
这个也是代码块
~~~
dotnil
2016-11-27 09:25:24 +08:00
@feather12315 你这是 liquid ,跟 markdown 没关系

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/323402

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX