Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 将一些标记数据从一个标记文件移动到不同的<;部门>;通过我的模板在html中创建部件_Ruby_Markdown_Jekyll_Middleman_Redcarpet - Fatal编程技术网

Ruby 将一些标记数据从一个标记文件移动到不同的<;部门>;通过我的模板在html中创建部件

Ruby 将一些标记数据从一个标记文件移动到不同的<;部门>;通过我的模板在html中创建部件,ruby,markdown,jekyll,middleman,redcarpet,Ruby,Markdown,Jekyll,Middleman,Redcarpet,如何使用我的html模板解析标记以切断或移动一些代码块从*.md到html 我有这样的降价文件: 胡萝卜汤 Very nice carrot soup ============ I'd like soup like this: ### Ingredients ### * carrots * celery * lentils ### Coocking ### Boil some water. And eat it with all Ingredient

如何使用我的html模板解析标记以切断或移动一些代码块从*.md到html

我有这样的降价文件: 胡萝卜汤

Very nice carrot soup
============

I'd like soup like this:

### Ingredients ###

      * carrots
      * celery
      * lentils

### Coocking ###

Boil some water. And eat it with all Ingredients
我需要将其解析为如下内容:

<div class="head"">
<h1>Very nice carrot soup</h1>
<p>I'd like soup like this:</p>
</div>
<!-- Something else -->

<div class="Ingredients">
<ul>
<li>carrots</li>
<li>celery</li>
<li>lentils</li>
</ul>
</div>

<div class="Coocking">
<p>Boil some water. And eat it with all Ingredients</p>
</div>
---
title: Very nice carrot soup
kind: recipe
created_at: 2013-10-03 1:59:00
author: fredrik
description: This is some really good carrot soup.....
---
### Ingredients ###

  * carrots
  * celery
  * lentils

### Cooking ###

Boil some water. And eat it with all Ingredients
回答问题
正如你的降价现在读到的,这是很难做到的,因为降价中没有任何东西可以让你提取部分内容。如果您不想更改标记格式(或者使用更适合的格式),那么您可以在客户端使用一点javascript(或者css)。将“其他东西”部分放在生成代码的末尾,并使用javascript找到的id。把它移到你想要的地方。如果您总是有一个名为“配料”的标题,那么您应该能够查询该元素并在其前面插入其他内容。如果你能忍受用div标记零件,那么它可能更安全

更好的选择 我不知道jekyll的情况,但我使用的nanoc有一个头文件,可以放在源文件中,从布局中提取信息。我会把标题和描述放在里面,然后在我的版面中把它们拿出来。nanoc标记文件如下所示:

<div class="head"">
<h1>Very nice carrot soup</h1>
<p>I'd like soup like this:</p>
</div>
<!-- Something else -->

<div class="Ingredients">
<ul>
<li>carrots</li>
<li>celery</li>
<li>lentils</li>
</ul>
</div>

<div class="Coocking">
<p>Boil some water. And eat it with all Ingredients</p>
</div>
---
title: Very nice carrot soup
kind: recipe
created_at: 2013-10-03 1:59:00
author: fredrik
description: This is some really good carrot soup.....
---
### Ingredients ###

  * carrots
  * celery
  * lentils

### Cooking ###

Boil some water. And eat it with all Ingredients
布局将提取标题和作者。片段:

<div class="head">
    <h1><%= @item[:title] %></h1>
    <p><%= @item[:description] %></p>
</div>
<%= add_some_more_stuff %>
<%= yield %>


你可能可以对jekyll做类似的事情。

请解释一下你所说的“切掉或移动一些块到html”是什么意思。您的示例表明,您只希望将标记解析并存储为html,asis。我需要将记录保存在标记文件中,我不知道如何使用html模板解析一些标记代码,以便使用jekyll或middleman构建静态html。例如,我有降价的代码。我如何告诉“中间人构建”理解我的降价文件并将一些代码解析为html的“div”部分?我如何在我的网站html模板中使用降价代码?您是否研究过使用?特别是我需要将一些标记数据从一个标记文件移动到html模板中的不同部分我了解如何使用标记“原样”转换为html,但如何通过模板将标记解析为html,将一些标记数据放到html模板的不同部分。要改变一些html代码。比如在html中使用erb。你是指这样的东西吗<代码>

好吧-收益部分给了你主要的降价,因为它是这样的,如果你想在那里有原料,你不需要将
@item[:配料]
也添加到布局中