如何使用Redcarpet和Markdown渲染表 [英] How to render table with Redcarpet and Markdown
本文介绍了如何使用Redcarpet和Markdown渲染表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Redcarpet渲染这样的表
I'm trying to render a table like this with Redcarpet
| header 1 | header 2 |
| -------- | -------- |
| cell 1 | cell 2 |
| cell 3 | cell 4 |
但是它不起作用.
是否可以使用Redcarpet渲染表格?
Is it possible to render a table with Redcarpet ?
推荐答案
是的,您可以渲染这样的表,但是必须启用:tables
选项.
Yes, you can render a table like that, but you have to enable the :tables
option.
require 'redcarpet'
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :tables => true)
text = <<END
| header 1 | header 2 |
| -------- | -------- |
| cell 1 | cell 2 |
| cell 3 | cell 4 |
END
puts markdown.render(text)
输出:
<table><thead>
<tr>
<th>header 1</th>
<th>header 2</th>
</tr>
</thead><tbody>
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</tbody></table>
这篇关于如何使用Redcarpet和Markdown渲染表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文