【问题标题】:Move some markdown data from one markdown file to different <div> parts in html via my template通过我的模板将一些降价数据从一个降价文件移动到 html 中的不同 <div> 部分
【发布时间】:2013-10-10 03:20:53
【问题描述】:

如何使用我的 html 模板解析 markdown 以将一些代码块从 *.md 截断或移动到 html?

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

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>

我需要将一些 markdown 数据从一个 markdown 文件移动到我的 html 模板中的不同部分

我有:

1) html 模板 2) 静态构建引擎 3) 带有降价代码的文件

在我的 html 模板中,我有一些 &lt;div&gt; 部分和 我需要将降价数据与 html 模板结合起来,而不是按原样。我需要削减一些降价代码并将此代码放入不同的 html &lt;div&gt; 部分。怎么办?

【问题讨论】:

  • 请解释您所说的“切断或移动一些块到 html”是什么意思。您的示例表明您只想将 Markdown 解析并存储为 html, asis.
  • 我需要将记录保存在 markdown 文件中,但我不明白如何使用我的 html 模板解析一些 markdown 代码,以便使用 jekyll 或中间人构建静态 html。例如,我在 markdown 中有代码。我如何告诉“中间人构建”理解我的降价文件并将一些代码解析为“div”部分到 html?如何在我的网站的 html 模板中使用降价代码?
  • 您探索过使用one of these gems 吗?特别是Redcarpet
  • 我需要将一些markdown数据从一个markdown文件移动到我的html模板中的不同
    部分
  • 我了解如何使用markdown“按原样”转换为html,但是如何通过模板将markdown解析为html以将一些markdown数据放入html模板的不同部分。在一些 html 代码周围有不同的
    。就像在 html 周围使用 erb。

标签: ruby markdown jekyll middleman redcarpet


【解决方案1】:

回答问题

正如您的降价现在所读的那样,这很难做到,因为降价中没有任何东西可以提取其中的一部分。如果您不想更改降价格式(或使用更适合此的格式),那么您可以在客户端使用一些 javascript(或者可能是 css)。将“其他”部分放在生成代码的末尾,并带有您使用 javascript 找到的 id。将其移动到您想要的位置。如果您始终有一个名为“成分”的标题,您应该能够查询该元素并在它之前插入其他内容。如果您可以忍受用 div 将 markdown parts 包装起来,那么它可能会更加安全。

更好的选择

我不知道 jekyll,但我使用的 nanoc 有一个标题,您可以将其放入源文件中,您可以从布局中提取信息。我会把标题和描述放在那里,然后在我的布局中把它们拉出来。 nanoc 降价文件如下所示:

---
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 做类似的事情。

【讨论】:

  • 你的意思是这样的? &lt;div class="sidebar"&gt; &lt;p&gt;&lt;%= @item[:ingredients] %&gt;&lt;/p&gt; &lt;/div&gt; &lt;%= add_some_more_stuff %&gt; &lt;div class="recepe_content"&gt; &lt;%= yield %&gt; &lt;/div&gt;
  • 好吧 - 产量部分给了你主要的降价,所以如果你想要那里的成分,你也不需要在布局中添加@item[:ingredients]
猜你喜欢
相关资源
最近更新 更多
热门标签