admin管理员组文章数量:1327975
I am wondering whether I can create my new website in markdown instead of in html. showdown.js at seems to be a plugin that can do this.
I am thinking something like
<html>
<head>
<script type="text/javascript" src="/js/showdown-starter.js" />
<link rel="StyleSheet" href="mystylesheet.css" type="text/css" />
</head>
<body>
# Wele
Hello. Wele to my website.
</body>
</html>
Presumably, the client javascript would transform this into html that the browser likes.
I am wondering whether I can create my new website in markdown instead of in html. showdown.js at https://github./coreyti/showdown seems to be a plugin that can do this.
I am thinking something like
<html>
<head>
<script type="text/javascript" src="/js/showdown-starter.js" />
<link rel="StyleSheet" href="mystylesheet.css" type="text/css" />
</head>
<body>
# Wele
Hello. Wele to my website.
</body>
</html>
Presumably, the client javascript would transform this into html that the browser likes.
Share Improve this question asked Dec 27, 2013 at 22:34 ivo Welchivo Welch 2,8862 gold badges28 silver badges40 bronze badges 1- Possibly helpful – Trojan Commented Dec 28, 2013 at 0:09
2 Answers
Reset to default 8Sure you can.
Here's an example how:
<div id="content">
# Wele
Hello. Wele to my **website**.
</div>
<script src="https://cdnjs.cloudflare./ajax/libs/showdown/1.4.0/showdown.min.js"></script>
<script>
var conv = new showdown.Converter();
var txt = document.getElementById('content').innerHTML;
console.log(txt);
document.getElementById('content').innerHTML = conv.makeHtml(txt);
</script>
I could be wrong but you might be better off doing the markdown-to-html conversion on the server side rather than on the client side. That would give the correct html to users who don't have javascript enabled, and it might make it easier for search engine bots to follow your links, reference your images, etc...
If you used the PHP port of Markdown to do that job, your example would look like this:
<body>
<?php
include("Markdown.php");
$text = <<<EOD
# Wele
Hello. Wele to my website.
EOD;
echo Markdown($text);
?>
</body>
本文标签: javascriptmarkdown in browser via showdownStack Overflow
版权声明:本文标题:javascript - markdown in browser via showdown - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742251238a2440801.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论