コード例 #1
0
ファイル: typygmentdown.py プロジェクト: gboue/django-util
    for block in code_blocks:
        
        #import pdb
        #pdb.set_trace()

        m = re.search(u"class=\"(?P<class_name>\w+)\">(?P<block_content>.*)</code>", block, re.DOTALL)
       
        block_content = u''
        if m:
            block_group = m.groupdict()
            block_content =  block_group['block_content']
            language = block_group['class_name']
        else:
            language = 'text'
        try:
            lexer = get_lexer_by_name(language, stripnl=True, encoding='UTF-8')
        except ValueError, e:
            try:
                lexer = guess_lexer(block.renderContents())
            except ValueError, e:
                lexer = get_lexer_by_name('text', stripnl=True, encoding='UTF-8')

        #block_soup = MinimalSoup(block)
        empty_code_blocks[index].replaceWith(
                highlight(block_content, lexer, formatter))
        index = index + 1
    # This is ugly, but it's the easiest way to kill extraneous paragraphs Markdown inserts.
    return unicode(soup).replace('<p><div', '<div').replace('</div>\n\n</p>', '</div>\n\n')

formatter.register('typygmentdown', typygmentdown)
コード例 #2
0
ファイル: wiki_markup.py プロジェクト: danigm/web-python-es
    # (e.g., all the regular expressions it uses are compiled)
    dialect = Creole(use_additions=True)
except ImportError:
    Creole = None

def creole(text, **kw):
    """Returns the text rendered by the Creole markup.
    """
    if Creole is None and settings.DEBUG:
        raise template.TemplateSyntaxError("Error in creole filter: "
            "The Creole library isn't installed, try easy_install Creoleparser.")
    parser = CreoleParser(dialect=dialect)
    return parser.render(text)

if Creole is not None:
    formatter.register('creole', creole)

register = template.Library()

@register.inclusion_tag('wiki/article_content.html')
def render_content(article, content_attr='content', markup_attr='markup'):
    """ Display an the body of an article, rendered with the right markup.

    - content_attr is the article attribute that will be rendered.
    - markup_attr is the article atribure with the markup that used
      on the article.

    Use examples on templates:

        {# article have a content and markup attributes #}
        {% render_content article %}
コード例 #3
0

def creole(text, **kw):
    """Returns the text rendered by the Creole markup.
    """
    if CreoleParser is None and settings.DEBUG:
        raise template.TemplateSyntaxError(
            "Error in creole filter: "
            "The Creole library isn't installed, try easy_install creole.")
    parser = CreoleParser(text)
    emitter = HtmlEmitter(parser.parse())
    return emitter.emit()


if CreoleParser is not None:
    formatter.register('creole', creole)

register = template.Library()


@register.inclusion_tag('wiki/article_content.html')
def render_content(article, content_attr='content', markup_attr='markup'):
    """ Display an the body of an article, rendered with the right markup.

    - content_attr is the article attribute that will be rendered.
    - markup_attr is the article atribure with the markup that used
      on the article.

    Use examples on templates:

        {# article have a content and markup attributes #}