Sha256: a9af7940da6c31b135c894c8b1ecaaa00f3b4d3323e06cace48753848aa12203

Contents?: true

Size: 1009 Bytes

Versions: 3

Compression:

Stored size: 1009 Bytes

Contents

#分析meta值
# http://pythonhosted.org/Markdown/extensions/meta_data.html

class Meta
    def initialize

    end

    #分析meta的部分
    def analysis_meta(original)
        return nil if not original

        result = Hash.new
        list = original.split(/[\r\n?]/)

        # 提取meta值
        list.each{ |line|
            next if line == ''
            next if (/^(\w+):(.+)/i =~ line) == nil

            key = $1.lstrip.rstrip
            value = $2.lstrip.rstrip

            result[key] = value
        }

        result
    end

    #分析内容
    def analysis(original)
        result = Hash.new

        pattern = /(\s+)?<!\-\-(.+?)\-\->(.+)?/m
        matches = pattern.match(original)

        #如果没有匹配到, 则body就是完整的original
        if matches == nil
            result['body'] = original
            return result
        end

        #获取body内容
        result['body'] = $3
        result['meta'] = self.analysis_meta $2
        result
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
m2m-0.2.3 lib/meta.rb
m2m-0.2.1 lib/meta.rb
m2m-0.2.0 lib/meta.rb