当前位置: 首页>>代码示例>>Python>>正文


Python jinja2.Markup方法代码示例

本文整理汇总了Python中jinja2.Markup方法的典型用法代码示例。如果您正苦于以下问题:Python jinja2.Markup方法的具体用法?Python jinja2.Markup怎么用?Python jinja2.Markup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jinja2的用法示例。


在下文中一共展示了jinja2.Markup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wikirender

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def wikirender(eval_ctx, wikicode):
    """
    Converts wikicode to the resulting HTML
    """
    r = requests.get('https://en.wikipedia.org/w/api.php',
        {'action':'parse',
         'text':wikicode,
         'format':'json',
        },
        timeout=30)
    result = r.json().get('parse',{}).get('text', {}).get('*','')

    result = result.replace('href="/wiki/',
            'href="https://en.wikipedia.org/wiki/')
    result = result.replace('<a ','<a target="_blank" ')

    if eval_ctx.autoescape:
        result = Markup(result) or wikicode
    return result or wikicode 
开发者ID:dissemin,项目名称:oabot,代码行数:21,代码来源:wikirender.py

示例2: register_extensions

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def register_extensions(app):
    """
    Register Flask extensions.
    """
    cache.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    ma.init_app(app)
    json_api.init_app(app)
    migrate.init_app(app, db)

    @app.context_processor
    def inject_debug():
        """
        Make the debug variable available to templates.
        """
        return dict(debug=app.debug, version=version)

    @app.template_filter()
    def safe_markdown(text):
        return jinja2.Markup(markdown.markdown(text))

    return None 
开发者ID:ewels,项目名称:MegaQC,代码行数:27,代码来源:app.py

示例3: sanitize_name

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def sanitize_name(value: str) -> str:
    """
    Sanitizes a value to be safe to store in a Linux filesystem, in
    S3, and in a URL.  So unicode is allowed, but not special
    characters other than ".", "-", and "_".

    This implementation is based on django.utils.text.slugify; it is
    modified by:
    * adding '.' and '_' to the list of allowed characters.
    * preserving the case of the value.
    """
    value = unicodedata.normalize('NFKC', value)
    value = re.sub(r'[^\w\s._-]', '', value, flags=re.U).strip()
    value = re.sub(r'[-\s]+', '-', value, flags=re.U)
    assert value not in {'', '.', '..'}
    return mark_safe(value) 
开发者ID:zulip,项目名称:zulip,代码行数:18,代码来源:upload.py

示例4: nl2br

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def nl2br(eval_ctx, value, make_urls=True):
    """
    Splits the provided string into paragraph tags based on the
    line breaks within it and returns the escaped result.

    Args:
        eval_ctx: The context used for filter evaluation.
        value: The string to process.
        make_urls: If True, will attempt to convert any URLs
            in the string to full links.

    Returns:
        The processed, escaped string.
    """
    result = get_nl2br(value, make_urls=make_urls)

    # Auto-escape if specified.
    if eval_ctx.autoescape:
        result = Markup(result)

    return result 
开发者ID:radremedy,项目名称:radremedy,代码行数:23,代码来源:remedyblueprint.py

示例5: phoneintl

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def phoneintl(eval_ctx, value):
    """
    Normalizes the provided phone number to a suitable
    international format.

    Args:
        eval_ctx: The context used for filter evaluation.
        value: The string to process.

    Returns:
        The processed phone number.
    """
    result = get_phoneintl(value)

    if eval_ctx.autoescape:
        result = Markup(result)

    return result 
开发者ID:radremedy,项目名称:radremedy,代码行数:20,代码来源:remedyblueprint.py

示例6: _create_jinja_environment

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def _create_jinja_environment(runfiles, site_root, link_ext):
  def _Load(path):
    loc = runfiles.Rlocation(posixpath.join(WORKSPACE_DIR, TEMPLATE_PATH, path))
    if loc:
      with open(loc, "rb") as f:
        return f.read().decode("utf-8")
    return None

  env = jinja2.Environment(
      loader=jinja2.FunctionLoader(_Load),
      keep_trailing_newline=True,
      line_statement_prefix='%')
  env.filters['markdown'] = lambda text: jinja2.Markup(mistune.markdown(text))
  env.filters['doc_link'] = (
      lambda fname: site_root + '/' + fname + '.' + link_ext)
  env.filters['link'] = lambda fname: site_root + '/' + fname
  return env


# TODO(dzc): Remove this workaround once we switch to a self-contained Python
# binary format such as PEX. 
开发者ID:bazelbuild,项目名称:skydoc,代码行数:23,代码来源:main.py

示例7: provider_login_url

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def provider_login_url(context, provider_id, **params):
    """
    {{ provider_login_url("persona", next="/some/url")}}
    {{ provider_login_url("github", next="/some/other/url")}}
    """
    request = context['request']
    provider = providers.registry.by_id(provider_id)
    auth_params = params.get('auth_params', None)
    scope = params.get('scope', None)
    process = params.get('process', None)
    if scope is '':
        del params['scope']
    if auth_params is '':
        del params['auth_params']
    if 'next' not in params:
        next = get_request_param(request, 'next')
        if next:
            params['next'] = next
        elif process == 'redirect':
            params['next'] = request.get_full_path()
    else:
        if not params['next']:
            del params['next']
    return jinja2.Markup(provider.get_login_url(request, **params)) 
开发者ID:mozilla,项目名称:feedthefox,代码行数:26,代码来源:helpers.py

示例8: markdown

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def markdown(*args):
    return Markup(md.convert(*args)) 
开发者ID:codeforamerica,项目名称:comport,代码行数:4,代码来源:template_globals.py

示例9: tojson_filter

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def tojson_filter(object_: Any, **kwargs: Any) -> Markup:
    return Markup(htmlsafe_dumps(object_, **kwargs)) 
开发者ID:pgjones,项目名称:quart,代码行数:4,代码来源:__init__.py

示例10: to_python

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def to_python(self, value: str) -> Markup:
        return Markup(value) 
开发者ID:pgjones,项目名称:quart,代码行数:4,代码来源:tag.py

示例11: render_cell

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def render_cell(value, database):
    # Render {"href": "...", "label": "..."} as link
    if not isinstance(value, str):
        return None
    stripped = value.strip()
    if not stripped.startswith("{") and stripped.endswith("}"):
        return None
    try:
        data = json.loads(value)
    except ValueError:
        return None
    if not isinstance(data, dict):
        return None
    if set(data.keys()) != {"href", "label"}:
        return None
    href = data["href"]
    if not (
        href.startswith("/")
        or href.startswith("http://")
        or href.startswith("https://")
    ):
        return None
    return jinja2.Markup(
        '<a data-database="{database}" href="{href}">{label}</a>'.format(
            database=database,
            href=jinja2.escape(data["href"]),
            label=jinja2.escape(data["label"] or "") or "&nbsp;",
        )
    ) 
开发者ID:simonw,项目名称:datasette,代码行数:31,代码来源:my_plugin_2.py

示例12: tojson_filter

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def tojson_filter(obj, **kwargs):
    return Markup(htmlsafe_dumps(obj, **kwargs)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:__init__.py

示例13: to_python

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def to_python(self, value):
        return Markup(value) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:tag.py

示例14: nl2br

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def nl2br(text):
  markup = jinja2.escape(text)
  return jinja2.Markup('<br>'.join(markup.split('\n'))) 
开发者ID:vijos,项目名称:vj4,代码行数:5,代码来源:misc.py

示例15: markdown

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Markup [as 别名]
def markdown(text):
  text = FS_RE.sub(fs_replace, text)
  return markupsafe.Markup(hoedown.html(
      text, extensions=MARKDOWN_EXTENSIONS, render_flags=MARKDOWN_RENDER_FLAGS)) 
开发者ID:vijos,项目名称:vj4,代码行数:6,代码来源:misc.py


注:本文中的jinja2.Markup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。