将MarkDown元素分组为DIV元素或自定义html标签 [英] Grouping MarkDown elements in to DIV element or Custom html tag

查看:282
本文介绍了将MarkDown元素分组为DIV元素或自定义html标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Jeykll工具将降价内容生成到HTMl中.

I have used Jeykll tool to generate mark down content into HTMl .

我想将以下标记元素归为div元素或任何其他自定义HTML标签.

I want to group the below mark down elements in to div element or any other custom Html tag.

 #Multiple Axis
    {:.title}
    Different types of data can be visualized in a single chart with the help of 
    {: .description}
    It can be used when we need to compare the trends of different kinds of data.
    {: .description}

HTML输出

  <h1 id="multiple-axis" class="title">Multiple Axis</h1>
    <p class="description">Different typ`enter code here`es of data can be visualized in a single chart with the help of</p>
    <p class="description">It can be used when we need to compare the trends of different kinds of data.</p>

如何将上述Markdown分组为Div元素或类似这样的任何自定义标签

How to group the above markdown into Div element or any custom tag like this

<div class="">    
     <h1 id="multiple-axis" class="title">Multiple Axis</h1>
        <p class="description">Different types of data can be visualized in a single chart with the help of</p>
        <p class="description">It can be used when we need to compare the trends of different kinds of data.</p>       
    </div>

推荐答案

答案部分取决于您所使用的Markdown解析器.碰巧,Jekyll支持一些不同的 Markdown解析器.并且您可能需要在用于启用适当功能的解析器上设置一些选项.

The answer depends in part on which Markdown parser you are using. As it happens, Jekyll supports a few different Markdown parsers. And you may need to set some options on the parser you are using to enable the appropriate features.

通常来说,Markdown要求您使用原始HTML来获取div.正如语法规则所述:

Generally speaking, Markdown requires you to use raw HTML to get a div. As the Syntax Rules explain:

Markdown不能替代HTML,甚至不能替代HTML.它的语法非常小,仅对应于很小的HTML标签子集.这个想法不是要创建一种使插入HTML标记更容易的语法.我认为HTML标记已经很容易插入. Markdown的想法是使其易于阅读,编写和编辑散文. HTML是一种发布格式; Markdown是一种书写格式.因此,Markdown的格式语法仅解决了可以以纯文本形式传达的问题.

Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags. The idea is not to create a syntax that makes it easier to insert HTML tags. In my opinion, HTML tags are already easy to insert. The idea for Markdown is to make it easy to read, write, and edit prose. HTML is a publishing format; Markdown is a writing format. Thus, Markdown’s formatting syntax only addresses issues that can be conveyed in plain text.

对于Markdown语法未涵盖的任何标记,只需使用HTML本身即可.

For any markup that is not covered by Markdown’s syntax, you simply use HTML itself.

但是,语法规则还规定:

However, the syntax rules also state:

请注意,Markdown格式语法未在块级HTML标记中处理.例如,您不能在HTML块内使用Markdown样式的*emphasis*.

换句话说,您需要将整个div及其中的所有内容定义为原始HTML.本质上,您需要从上面的问题中复制所需的输出,并将其粘贴到Markdown文档中.

In other words, you would need to define the entire div and everything in it as raw HTML. Essentially, you would need to copy your desired output from your question above and paste that into the Markdown document.

但是,某些Markdown解析器已添加了允许各种快捷方式的其他功能.例如,您使用的解析器似乎支持将属性分配给文档的各个部分,而又不依赖原始HTML -这使我相信您可能正在使用Kramdown,该文档记录了对

However, some Markdown parsers have added additional functionality which allows various shortcuts. For example, it appears that the parser you are using supports assigning attributes to the various parts of a document without falling back to raw HTML -- which leads me to believe that you are probably using Kramdown which has documented support for attribute lists.

事实证明,Kramdown还包括可选支持,用于解析 HTML块.当文档解释所有选项时,基本思想是,如果在原始HTML标签上设置markdown=1属性,则该标签的内容将被解析为HTML.像这样:

As it turns out, Kramdown also includes optional support for parsing Markdown content inside HTML Blocks. While the docs explain all of the options, the basic idea is that if you set an attribute of markdown=1 on the raw HTML tag, then the content of that tag will be parsed as HTML. Like this:

<div markdown=1>
This will get parsed as *Markdown* content.
</div>

这将生成以下HTML输出:

Which would generate the following HTML output:

<div>
<p>This will get parsed as <emphasis>Markdown</emphasis> content.</p>
</div>

当然,您也可以在div上分配一个类.因此,您的最终文档将如下所示:

Of course, you can then assign a class on your div as well. Therefore, you final document would look like this:

<div class="someclass" markdown=1>

#Multiple Axis
{:.title}

Different types of data can be visualized in a single chart with the help of 
{: .description}

It can be used when we need to compare the trends of different kinds of data.
{: .description}

#Multiple Axis
{:.title}

Different types of data can be visualized in a single chart with the help of 
{: .description}

It can be used when we need to compare the trends of different kinds of data.
{: .description}

</div>

当然,如果您使用其他Markdown解析器,则需要查阅该解析器的文档,以了解它是否支持类似的非标准功能.

Of course, if you are using a different Markdown parser, you will need to consult that parser's documentation to see if it supports a similar non-standard feature.

这篇关于将MarkDown元素分组为DIV元素或自定义html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆