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
Add a ment  | 

2 Answers 2

Reset to default 8

Sure 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