Beispiel #1
0
    def parse_post(self):
        if hasattr(self, 'post'):
            return self.post
        parts = MarkdownParser(self.filepath).read()

        post = NameSpace(parts)
        tags = post.get('tags', None)
        if tags:
            post.tags = [tag.strip() for tag in tags.split(',')]
        self.post = post
        return post
Beispiel #2
0
    def parse_post(self):
        if hasattr(self, 'post'):
            return self.post
        parts = MarkdownParser(self.filepath).read()

        post = NameSpace(parts)
        tags = post.get('tags', None)
        if tags:
            post.tags = [tag.strip() for tag in tags.split(',')]
        self.post = post
        return post
Beispiel #3
0
    def parse_post(self):
        if hasattr(self, 'post'):
            return self.post

        parts = rstParser(self.filepath).read()
        docinfo = dict(parts['docinfo'])

        post = NameSpace()
        for k, v in docinfo.items():
            post[k] = v
        post.title = parts['title']
        post.content = parts['body']
        self.post = post
        return post
Beispiel #4
0
    def parse_post(self):
        if hasattr(self, 'post'):
            return self.post

        parts = rstParser(self.filepath).read()
        docinfo = dict(parts['docinfo'])

        post = NameSpace()
        for k, v in docinfo.items():
            post[k] = v
        post.title = parts['title']
        post.content = parts['body']
        self.post = post
        return post
Beispiel #5
0
 def calc_tagcloud(self):
     tagcloud = merge(self.calc_tag_posts())
     for k, v in tagcloud.items():
         tag = NameSpace(
             name=k,
             count=len(v),
             size=100 + log(len(v) or 1) * 20,
         )
         yield tag
Beispiel #6
0
    def repl(m):
        try:
            lexer = get_lexer_by_name(m.group(1))
        except ValueError:
            lexer = TextLexer()
        code = highlight(m.group(2), lexer, formatter)
        code = code.replace('\n\n', '\n&nbsp;\n').replace('\n', '<br />')
        return '\n\n<div class="code">%s</div>\n\n' % code

    return pattern.sub(repl, text)


markdown_prefork = NameSpace({
    'codeblock': 'liquidluck.readers.mkd.codeblock',
    'youku': 'liquidluck.filters.youku',
    'tudou': 'liquidluck.filters.tudou',
    'yinyuetai': 'liquidluck.filters.yinyuetai',
})


def markdown(text):
    if 'markdown_prefork' in ns.sections:
        markdown_prefork.update(ns.sections.markdown_prefork)

    for module in markdown_prefork.values():
        if module:
            text = import_module(module)(text)
    md = Markdown()
    return md.convert(text)