HTML inside Markdown

I am trying to use a bunch of text files + vim + Markdown.pl as an efficient platform for taking notes. So far, I am pleased with the Markdown.pl parser. But the line seems to be

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

converted to:

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

Is there something I am missing?

+4
source share
6 answers

The main thing that you are missing is that Markdown is not really designed as a template system, but the syntax of simple text formatting. If you want to include HTML material such as style sheets, you'd better use something like Haml .

Another solution would be to create a simple HTML template around your formatted Markdown content, for example (PHP example, but can be in any language).

 <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> 
+5
source

Markdown.pl in its latest version does not accept link tags as block tags and therefore tries to wrap them in <p> tags.

To fix this, add the word β€œlink” to the block regex lists on line 323 so they look 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, but the result is work link tags.

+2
source

If markdown.pl meets the specification, this should be possible.

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

:) Teo

+2
source

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

Try this markdown:

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

This translates to:

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

If you can do everything in one block, you will get one <p></p> . I'm not sure you can avoid this with markdowns.

+1
source

You need

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

if you are trying to use it as a style sheet (if you want, try to find it here ) (I'm not sure where the markdown goes to it, I don’t know anything about markdown).

Is that how you want to use it?

0
source

One easy way is to insert </p> before and <p> after your HTML tag:

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

This translates to:

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

It still adds paragraphs, but helps your tags fall into the correct hierarchy. For some browsers this may be needed. One thing that should be taken care of is not to use double newlines or any markdown pointers.

0
source

Source: https://habr.com/ru/post/1395953/


All Articles