3

I am wondering whether I can create my new website in markdown instead of in html. showdown.js at https://github.com/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>

 # Welcome

 Hello.  Welcome to my website.

 </body>
 </html>

Presumably, the client javascript would transform this into html that the browser likes.

ivo Welch
  • 2,427
  • 2
  • 23
  • 31

2 Answers2

8

Sure you can.

Here's an example how:

<div id="content">
# Welcome

Hello.  Welcome to my **website**.
</div>
<script src="https://cdnjs.cloudflare.com/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>
Tivie
  • 18,864
  • 5
  • 58
  • 77
  • Tried this, is a good solution but also has limitations. Not so good in converting code tag elements. The php solution below is the best for converting code tag elements – Omari Victor Omosa Sep 12 '16 at 18:04
  • @krushiovida what problems did you encounter converting code elements? – Tivie Oct 18 '16 at 01:42
1

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

# Welcome

Hello.  Welcome to my website.

EOD;
echo Markdown($text);
?>
</body>
pevinkinel
  • 391
  • 3
  • 17
  • good idea, but my 1000 browsers have way more computing power than my single server. (maybe this doesn't matter...would need to assess and benchmark) – ivo Welch Dec 29 '13 at 17:28
  • very good point. You're right, on a big scale it would only be practical with some caching system. But somehow, I still think something is wrong with trusting the client to do the job. I can't quite explain why. – pevinkinel Dec 30 '13 at 00:41