當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。