Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML inside Markdown

Tags:

html

css

markdown

I'm trying to use a bunch of text files + vim + Markdown.pl as an efficient note taking platform. I've been happy with the Markdown.pl parser so far. But a line like,

<link href="style.css" rel="stylesheet"></link>

gets converted into:

<p><link href="style.css" rel="stylesheet"></link></p>

Is there something that I am missing?

like image 298
pewfly Avatar asked Feb 11 '12 18:02

pewfly


4 Answers

The main thing you're missing is that Markdown is not really designed as a templating system, but a plain text formatting syntax. If you want to include HTML stuff like stylesheets, you're better off using something like Haml.

Another solution would be to create a plain HTML template around your Markdown formatted content like so (PHP example, but could be in any language ofcourse).

<html>
<head>
    <title>My Notes</title>
    <link href="style.css" rel="stylesheet">
</head>
<body>
    <h1>My notes</h1>
    <?php markdown(file_get_contents('your_content.md')); ?>
</body>
like image 139
vindia Avatar answered Oct 20 '22 00:10

vindia


If markdown.pl complies with the specification it should be possible.

The "Inline HTML" section of the documentation, markdown syntax, states that your html "must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces".

like image 26
Teo Sartori Avatar answered Oct 19 '22 22:10

Teo Sartori


Markdown wraps everything it considers a paragraph into <p></p>. Try it here:

  • http://daringfireball.net/projects/markdown/dingus

Try this markdown:

 hello **this is going to be bold**<link href="style.css" rel="stylesheet"></link>

This will get converted to:

<p>hello
<strong>this is going to be bold</strong><link href="style.css" rel="stylesheet"></link></p>

If you can make everything be one block, you'll get one <p></p>. I'm not sure you can avoid this with markdown.

like image 2
icyrock.com Avatar answered Oct 20 '22 00:10

icyrock.com


Markdown.pl, in its most recent version, does not accept link tags as block tags, and so it tries to wrap them in <p> tags.

To correct this, add the word 'link' into the block tag regex lists on line 323, so they end up looking like this:

my $block_tags_a = qr/p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del|link/;
my $block_tags_b = qr/p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|link/;

You may not have to do both of them, but the result is working link tags.

like image 2
Falcolas Avatar answered Oct 20 '22 00:10

Falcolas