简体   繁体   English

将MarkDown元素分组为DIV元素或自定义html标签

[英]Grouping MarkDown elements in to DIV element or Custom html tag

I have used Jeykll tool to generate mark down content into HTMl . 我已经使用Jeykll工具将markdown内容生成到HTMl中。

I want to group the below mark down elements in to div element or any other custom Html tag. 我想将下面的标记元素分组到div元素或任何其他自定义HTML标签中。

Marked Down 记下来

 #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 Output 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>

How to group the above markdown into Div element or any custom tag like this 如何将上述markdown分组为Div元素或类似这样的任何自定义标签

<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>

The answer depends in part on which Markdown parser you are using. 答案部分取决于您使用的Markdown解析器。 As it happens, Jekyll supports a few different Markdown parsers . 碰巧,Jekyll支持一些不同的Markdown解析器 And you may need to set some options on the parser you are using to enable the appropriate features. 您可能需要在使用的解析器上设置一些选项以启用适当的功能。

Generally speaking, Markdown requires you to use raw HTML to get a div. 一般来说,Markdown要求您使用原始HTML来获取div。 As the Syntax Rules explain: 正如语法规则所解释的:

Markdown is not a replacement for HTML, or even close to it. Markdown不能替代HTML,甚至不能替代HTML。 Its syntax is very small, corresponding only to a very small subset of HTML tags. 它的语法非常小,仅对应于很小的HTML标签子集。 The idea is not to create a syntax that makes it easier to insert HTML tags. 这个想法不是要创建一种使插入HTML标签更加容易的语法。 In my opinion, HTML tags are already easy to insert. 我认为HTML标记已经很容易插入。 The idea for Markdown is to make it easy to read, write, and edit prose. Markdown的想法是使散文易于阅读,编写和编辑。 HTML is a publishing format; HTML是一种发布格式; Markdown is a writing format. Markdown是一种书写格式。 Thus, Markdown's formatting syntax only addresses issues that can be conveyed in plain text. 因此,Markdown的格式语法仅解决可以以纯文本形式传达的问题。

For any markup that is not covered by Markdown's syntax, you simply use HTML itself. 对于Markdown语法未涵盖的任何标记,您只需使用HTML本身。

However, the syntax rules also state: 但是,语法规则还规定:

Note that Markdown formatting syntax is not processed within block-level HTML tags. 请注意,Markdown格式语法不会在块级HTML标记中处理。 Eg, you can't use Markdown-style *emphasis* inside an HTML block. 例如,您不能在HTML块内使用Markdown样式*emphasis*

In other words, you would need to define the entire div and everything in it as raw HTML. 换句话说,您需要将整个div及其中的所有内容定义为原始HTML。 Essentially, you would need to copy your desired output from your question above and paste that into the Markdown document. 本质上,您需要从上述问题中复制所需的输出,并将其粘贴到Markdown文档中。

However, some Markdown parsers have added additional functionality which allows various shortcuts. 但是,某些Markdown解析器已添加了其他功能,允许使用各种快捷方式。 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 . 例如,您正在使用的解析器似乎支持将属性分配给文档的各个部分,而又不依赖原始HTML -这使我相信您可能正在使用Kramdown,该文档记录了对属性列表的支持。

As it turns out, Kramdown also includes optional support for parsing Markdown content inside HTML Blocks . 事实证明,Kramdown还包括对HTML块内Markdown内容进行解析的可选支持。 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. 当文档解释所有选项时,基本思想是,如果在原始HTML标签上设置markdown=1的属性,则该标签的内容将被解析为HTML。 Like this: 像这样:

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

Which would generate the following HTML output: 这将生成以下HTML输出:

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

Of course, you can then assign a class on your div as well. 当然,您也可以在div上分配一个类。 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>

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解析器,则需要查阅该解析器的文档,以查看其是否支持类似的非标准功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM