Pregunta

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.

¿Fue útil?

Solución

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>

Otros consejos

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>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top