Pages

Thursday, 20 February 2014

用PostModern输出html文件

Write Haml in Markdown, Syntax Highlight with Pygments, and Pretty Print the output HTML, in Ruby.

Install

gem install post-modern

Usage

---
title: My Post
tags: a, b, c
---

Here's a table of stuff:

@@@ haml
%table
  %thead
    %tr
      %th Column A
      %th Column B
  %tbody
    %tr
      %td Item A
      %td Item B
@@@

This table is:

1. written in Haml
2. compiled to html, along with the markdown
require 'post-modern'

post = Post.read("docs/my-post.md")
{
  :title     => "My Post",
  :tags      => ["a", "b", "c"], 
  :format    => "markdown", 
  :keywords  => [], 
  :slug      => "my-post", 
  :file      => "post.md", 
  :published => false
  :content   => %{
<p>Here's a table of stuff:</p>
<table>
  <thead>
    <tr>
      <th>Column A</th>
      <th>Column B</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Item A</td>
      <td>Item B</td>
    </tr>
  </tbody>
</table>
<p>This table is:</p>
<ol>
  <li>written in Haml</li>
  <li>compiled to html, along with the markdown</li>
</ol>}
}
If you have github style code blocks (3 backticks with lang surrounding code), it will be run through the pygments syntax highlighter (requires python). It's really easy to then use Guard to watch as files change, and update your records by parsing the content with this。

from https://github.com/viatropos/post-modern