Markdown 中的 HTML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9243104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML inside Markdown
提问by pewfly
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,
我正在尝试使用一堆文本文件 + vim + Markdown.pl 作为一个高效的笔记平台。到目前为止,我对 Markdown.pl 解析器很满意。但是像这样的一行,
<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?
有什么我想念的吗?
回答by vindia
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.
您缺少的主要内容是 Markdown 并不是真正设计为模板系统,而是纯文本格式语法。如果您想包含样式表之类的 HTML 内容,最好使用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).
另一种解决方案是围绕 Markdown 格式的内容创建一个纯 HTML 模板,如下所示(PHP 示例,但可以是任何语言)。
<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>
回答by Falcolas
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.
Markdown.pl 在其最新版本中不接受链接标签作为块标签,因此它尝试将它们包装在<p>
标签中。
To correct this, add the word 'link' into the block tag regex lists on line 323, so they end up looking like this:
要更正此问题,请将“链接”一词添加到第 323 行的块标记正则表达式列表中,因此它们最终看起来像这样:
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.
您可能不必同时执行这两项操作,但结果是可以使用链接标记。
回答by Teo Sartori
If markdown.pl
complies with the specification it should be possible.
如果markdown.pl
符合规范,应该是可以的。
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".
文档的“内联 HTML”部分,markdown 语法,指出您的 html“必须通过空行与周围的内容分开,并且块的开始和结束标记不应使用制表符或空格缩进”。
回答by icyrock.com
Markdown wraps everything it considers a paragraph into <p></p>
. Try it here:
Markdown 将它认为是段落的所有内容包装到<p></p>
. 在这里试试:
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.
如果你能把所有东西都变成一个方块,你就会得到一个<p></p>
。我不确定您是否可以通过降价来避免这种情况。
回答by ACarter
You need
你需要
<link href="style.css" type="text/css" rel="stylesheet"></link>
if you are trying to use it as a stylesheet (if you are, try looking here) (I'm not sure where markdown comes into it, I know nothing about markdown).
如果您尝试将其用作样式表(如果是,请尝试查看此处)(我不确定 Markdown 的来源,我对 Markdown 一无所知)。
Is this how you are looking to use it?
这是您希望使用它的方式吗?
回答by Nandakumar Edamana
One simple workaround is to insert a </p>
before and <p>
after your HTML tag:
一种简单的解决方法是在 HTML 标记</p>
之前和<p>
之后插入一个:
</p><link href="style.css" rel="stylesheet"></link><p>
This will get converted to:
这将转换为:
<p></p><link href="style.css" rel="stylesheet"></link><p></p>
It still adds paragraphs, but helps your tags to get into the right hierarchy. Some browsers may need it. One thing to take care is not to use double newlines or any markdown-specific punctuators.
它仍然添加了段落,但可以帮助您的标签进入正确的层次结构。某些浏览器可能需要它。需要注意的一件事是不要使用双换行符或任何特定于降价的标点符号。