使用以下代码,我得到工作输出:
<html>
<head>
<script type="text/javascript" src="/js/showdown.js"></script>
</head>
<body>
<script type="text/javascript">
var converter = new Showdown.converter();
alert(converter.makeHtml('*test* abc'));
</script>
</body>
</html>
返回<p><em>test</em> abc</p>
我现在想添加一个扩展。github页面建议这可以通过以下方式完成:
<script src="src/extensions/twitter.js" />
var converter = new Showdown.converter({ extensions: 'twitter' });
但是,将我的代码修改为:
<html>
<head>
<script type="text/javascript" src="/js/showdown.js"></script>
<script type="text/javascript" src="/js/twitter.js"></script>
</head>
<body>
<script type="text/javascript">
var converter = new Showdown.converter({ extensions: 'twitter' });
alert(converter.makeHtml('*test* abc'));
</script>
</body>
</html>
产生错误
"Uncaught Extension 'undefined' could not be loaded. It was either not found or is not a valid extension."
添加以下代码(如过滤器示例下所列)
var demo = function(converter) {
return [
// Replace escaped @ symbols
{ type: 'lang', function(text) {
return text.replace(/\\@/g, '@');
}}
];
}
产生错误Uncaught SyntaxError: Unexpected token (
我想创建一个像https://github.com/rennat/python-markdown-oembed这样的扩展来解释 a ![video](youtube_link)
,但目前还不清楚如何开始添加这种支持。