示例#1
0
def format_enriched_text(datamanager, content, initial_header_level=None, report_level=None, excluded_link=None):
    """
    Converts RST content to HTML and adds encyclopedia links.
    
    *excluded_link* is the ENCYCLOPEDIA article_id in which we currently are, if any.
    """
    assert isinstance(content, basestring)

    content = content.replace("[INSTANCE_ID]", datamanager.game_instance_id) # handy to build URLs manually

    with exception_swallower():
        content = _generate_game_file_links(content, datamanager) # BEFORE html
    with exception_swallower():
        content = _generate_game_image_thumbnails(content, datamanager) # BEFORE html

    html = advanced_restructuredtext(content, initial_header_level=initial_header_level, report_level=report_level)

    #print(">>>format_enriched_text>>>>>", html)
    with exception_swallower():
        html = _generate_encyclopedia_links(html, datamanager, excluded_link=excluded_link)
    with exception_swallower():
        html = _generate_messaging_links(html, datamanager)
    with exception_swallower():
        html = _generate_site_links(html, datamanager) # o

    html = html.replace("[BR]", "<br />") # line breaks, handy for vertical spacing
    html = html.replace("[NBSP]", unichr(160)) # non-breaking spaces, handy for punctuation mainly

    return html
示例#2
0
def render_restructuredtext(context,
                            content,
                            initial_header_level=None,
                            report_level=None):
    html = advanced_restructuredtext(content,
                                     initial_header_level=initial_header_level,
                                     report_level=report_level)
    with exception_swallower(
    ):  # FIXME - make it depend on game language, one day
        html = french_insecable(
            html)  # handles non-breaking spaces, especially
    return mark_safe(html)
示例#3
0
def format_enriched_text(datamanager,
                         content,
                         initial_header_level=None,
                         report_level=None,
                         excluded_link=None,
                         text_format=None):
    """
    Converts RST content to HTML and adds encyclopedia links.
    
    *excluded_link* is the ENCYCLOPEDIA article_id in which we currently are, if any.
    """
    assert isinstance(content, str)

    #print(">>>format_enriched_text", content[:30], "----", excluded_link)

    # we leave RestructuredRext as the DEFAULT format for game contents
    text_format = text_format or datamanager.AVAILABLE_TEXT_FORMATS.rst

    content = content.replace(
        "[INSTANCE_ID]",
        datamanager.game_instance_id)  # handy to build URLs manually

    with exception_swallower():
        content = _generate_game_file_links(content,
                                            datamanager)  # BEFORE html
    with exception_swallower():
        content = _generate_game_image_thumbnails(content,
                                                  datamanager)  # BEFORE html

    if text_format == datamanager.AVAILABLE_TEXT_FORMATS.rst:
        html = advanced_restructuredtext(
            content,
            initial_header_level=initial_header_level,
            report_level=report_level)
    else:
        assert text_format in (None, datamanager.AVAILABLE_TEXT_FORMATS.raw)
        html = linebreaks(content)  # only adds <p> and <br> tags

    #print(">>>format_enriched_text>>>>>", html)
    with exception_swallower():
        html = _generate_encyclopedia_links(html,
                                            datamanager,
                                            excluded_link=excluded_link)
    with exception_swallower():
        html = _generate_messaging_links(html, datamanager)
    with exception_swallower():
        html = _generate_site_links(html, datamanager)
    with exception_swallower(
    ):  #FIXME - make it depend on game language, one day
        html = french_insecable(
            html)  # handles non-breaking spaces, especially

    # note that conf-enforced RST roles might be used too (|BR|, |NBSP|)...
    html = html.replace("[BR]",
                        "<br />")  # line breaks, handy for vertical spacing
    html = html.replace(
        "[NBSP]",
        chr(160))  # non-breaking spaces, handy for punctuation mainly

    return html
示例#4
0
def usercolor(context, username_or_email):
    """
    Determines if an HTML color is attached to the user/email, or returns None instead.
    """
    color = None
    with exception_swallower():
        request = context.get('request')
        if "@" in username_or_email:
            username = request.datamanager.get_character_or_none_from_email(username_or_email)
        else:
            username = username_or_email
        color = request.datamanager.get_character_color_or_none(username)
    return color or "black" # default color
示例#5
0
def format_enriched_text(datamanager, content, initial_header_level=None, report_level=None, excluded_link=None, text_format=None):
    """
    Converts RST content to HTML and adds encyclopedia links.
    
    *excluded_link* is the ENCYCLOPEDIA article_id in which we currently are, if any.
    """
    assert isinstance(content, basestring)

    #print(">>>format_enriched_text", content[:30], "----", excluded_link)

    # we leave RestructuredRext as the DEFAULT format for game contents
    text_format = text_format or datamanager.AVAILABLE_TEXT_FORMATS.rst

    content = content.replace("[INSTANCE_ID]", datamanager.game_instance_id) # handy to build URLs manually

    with exception_swallower():
        content = _generate_game_file_links(content, datamanager) # BEFORE html
    with exception_swallower():
        content = _generate_game_image_thumbnails(content, datamanager) # BEFORE html

    if text_format == datamanager.AVAILABLE_TEXT_FORMATS.rst:
        html = advanced_restructuredtext(content, initial_header_level=initial_header_level, report_level=report_level)
    else:
        assert text_format in (None, datamanager.AVAILABLE_TEXT_FORMATS.raw)
        html = linebreaks(content)  # only adds <p> and <br> tags

    #print(">>>format_enriched_text>>>>>", html)
    with exception_swallower():
        html = _generate_encyclopedia_links(html, datamanager, excluded_link=excluded_link)
    with exception_swallower():
        html = _generate_messaging_links(html, datamanager)
    with exception_swallower():
        html = _generate_site_links(html, datamanager) # o

    html = html.replace("[BR]", "<br />") # line breaks, handy for vertical spacing
    html = html.replace("[NBSP]", unichr(160)) # non-breaking spaces, handy for punctuation mainly

    return html
示例#6
0
def usercolor(context, username_or_email):
    """
    Determines if an HTML color is attached to the user/email, or returns None instead.
    """
    color = None
    with exception_swallower():
        request = context.get('request')
        if "@" in username_or_email:
            username = request.datamanager.get_character_or_none_from_email(
                username_or_email)
        else:
            username = username_or_email
        color = request.datamanager.get_character_color_or_none(username)
    return color or "black"  # default color