• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python filters.typogrify函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中typogrify.filters.typogrify函数的典型用法代码示例。如果您正苦于以下问题:Python typogrify函数的具体用法?Python typogrify怎么用?Python typogrify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: read_file

def read_file(filename, fmt=None, settings=None):
    """Return a reader object using the given format."""
    if not fmt:
        fmt = filename.split('.')[-1]

    if fmt not in _EXTENSIONS:
        raise TypeError('Pelican does not know how to parse %s' % filename)

    reader = _EXTENSIONS[fmt](settings)
    settings_key = '%s_EXTENSIONS' % fmt.upper()

    if settings and settings_key in settings:
        reader.extensions = settings[settings_key]

    if not reader.enabled:
        raise ValueError("Missing dependencies for %s" % fmt)

    content, metadata = reader.read(filename)

    # eventually filter the content with typogrify if asked so
    if settings and settings['TYPOGRIFY']:
        from typogrify.filters import typogrify
        content = typogrify(content)
        metadata['title'] = typogrify(metadata['title'])

    return content, metadata
开发者ID:bstpierre,项目名称:pelican,代码行数:26,代码来源:readers.py


示例2: read_file

def read_file(path, fmt=None, settings=None):
    """Return a reader object using the given format."""
    base, ext = os.path.splitext(os.path.basename(path))
    if not fmt:
        fmt = ext[1:]

    if fmt not in EXTENSIONS:
        raise TypeError('Pelican does not know how to parse {}'.format(path))

    if settings is None:
        settings = {}

    reader = EXTENSIONS[fmt](settings)
    settings_key = '%s_EXTENSIONS' % fmt.upper()

    if settings and settings_key in settings:
        reader.extensions = settings[settings_key]

    if not reader.enabled:
        raise ValueError("Missing dependencies for %s" % fmt)

    metadata = parse_path_metadata(
        path=path, settings=settings, process=reader.process_metadata)
    content, reader_metadata = reader.read(path)
    metadata.update(reader_metadata)

    # eventually filter the content with typogrify if asked so
    if content and settings and settings.get('TYPOGRIFY'):
        from typogrify.filters import typogrify
        content = typogrify(content)
        metadata['title'] = typogrify(metadata['title'])

    return content, metadata
开发者ID:AndreLesa,项目名称:pelican,代码行数:33,代码来源:readers.py


示例3: typogrify_wrapper

 def typogrify_wrapper(text):
     """Ensures ignore_tags feature is backward compatible"""
     try:
         return typogrify(
             text,
             self.settings['TYPOGRIFY_IGNORE_TAGS'])
     except TypeError:
         return typogrify(text)
开发者ID:andrew-vant,项目名称:pelican,代码行数:8,代码来源:readers.py


示例4: _postprocess

 def _postprocess(self):
     if self.rc.get('typogrify', False):
         if self.output:
             self.output = typogrify(self.output)
         if 'title' in self.meta:
             self.meta['title'] = typogrify(self.meta['title'])
     if 'tags' in self.meta:
         self.meta['tags'] = [t.strip() for t in self.meta['tags'].split(',')]
开发者ID:dmdm,项目名称:PySite,代码行数:8,代码来源:textconv.py


示例5: read_file

    def read_file(self, base_path, path, content_class=Page, fmt=None,
                  context=None, preread_signal=None, preread_sender=None,
                  context_signal=None, context_sender=None):
        """Return a content object parsed with the given format."""

        path = os.path.abspath(os.path.join(base_path, path))
        source_path = os.path.relpath(path, base_path)
        logger.debug('read file {} -> {}'.format(
            source_path, content_class.__name__))

        if not fmt:
            _, ext = os.path.splitext(os.path.basename(path))
            fmt = ext[1:]

        if fmt not in self.readers:
            raise TypeError(
                'Pelican does not know how to parse {}'.format(path))

        if preread_signal:
            logger.debug('signal {}.send({})'.format(
                preread_signal, preread_sender))
            preread_signal.send(preread_sender)

        reader = self.readers[fmt]

        metadata = default_metadata(
            settings=self.settings, process=reader.process_metadata)
        metadata.update(path_metadata(
            full_path=path, source_path=source_path,
            settings=self.settings))
        metadata.update(parse_path_metadata(
            source_path=source_path, settings=self.settings,
            process=reader.process_metadata))

        content, reader_metadata = reader.read(path)
        metadata.update(reader_metadata)

        if content:
            # find images with empty alt
            find_empty_alt(content, path)

        # eventually filter the content with typogrify if asked so
        if self.settings['TYPOGRIFY']:
            from typogrify.filters import typogrify
            if content:
                content = typogrify(content)
                metadata['title'] = typogrify(metadata['title'])
            if 'summary' in metadata:
                metadata['summary'] = typogrify(metadata['summary'])

        if context_signal:
            logger.debug('signal {}.send({}, <metadata>)'.format(
                context_signal, context_sender))
            context_signal.send(context_sender, metadata=metadata)

        return content_class(content=content, metadata=metadata,
                             settings=self.settings, source_path=path,
                             context=context)
开发者ID:al-tonio,项目名称:pelican,代码行数:58,代码来源:readers.py


示例6: read_file

def read_file(
    base_path,
    path,
    content_class=Page,
    fmt=None,
    settings=None,
    context=None,
    preread_signal=None,
    preread_sender=None,
    context_signal=None,
    context_sender=None,
):
    """Return a content object parsed with the given format."""
    path = os.path.abspath(os.path.join(base_path, path))
    source_path = os.path.relpath(path, base_path)
    base, ext = os.path.splitext(os.path.basename(path))
    logger.debug("read file {} -> {}".format(source_path, content_class.__name__))
    if not fmt:
        fmt = ext[1:]

    if fmt not in EXTENSIONS:
        raise TypeError("Pelican does not know how to parse {}".format(path))

    if preread_signal:
        logger.debug("signal {}.send({})".format(preread_signal, preread_sender))
        preread_signal.send(preread_sender)

    if settings is None:
        settings = {}

    reader_class = EXTENSIONS[fmt]
    if not reader_class.enabled:
        raise ValueError("Missing dependencies for {}".format(fmt))

    reader = reader_class(settings)

    settings_key = "%s_EXTENSIONS" % fmt.upper()

    if settings and settings_key in settings:
        reader.extensions = settings[settings_key]

    metadata = default_metadata(settings=settings, process=reader.process_metadata)
    metadata.update(path_metadata(full_path=path, source_path=source_path, settings=settings))
    metadata.update(parse_path_metadata(source_path=source_path, settings=settings, process=reader.process_metadata))
    content, reader_metadata = reader.read(path)
    metadata.update(reader_metadata)

    # eventually filter the content with typogrify if asked so
    if content and settings and settings["TYPOGRIFY"]:
        from typogrify.filters import typogrify

        content = typogrify(content)
        metadata["title"] = typogrify(metadata["title"])

    if context_signal:
        logger.debug("signal {}.send({}, <metadata>)".format(context_signal, context_sender))
        context_signal.send(context_sender, metadata=metadata)
    return content_class(content=content, metadata=metadata, settings=settings, source_path=path, context=context)
开发者ID:pnewman1,项目名称:pelican,代码行数:58,代码来源:readers.py


示例7: typogrify

 def typogrify(self):
     """filter the content with typogrify"""
     if self._settings.get('TYPOGRIFY', False):
         from typogrify.filters import typogrify
         if self._content:
             self._content = typogrify(self._content)
             self._metadata['title'] = typogrify(self._metadata['title'])
         if 'summary' in self._metadata:
             self._metadata['summary'] = typogrify(self._metadata['summary'])
开发者ID:finklabs,项目名称:buccaneer,代码行数:9,代码来源:contents.py


示例8: process_content

def process_content(instance):
    """Processes content, with logic to ensure that typogrify does not clash
    with math.

    In addition, mathjax script is inserted at the end of the content thereby
    making it independent of the template
    """

    if not instance._content:
        return

    ignore_within = ignore_content(instance._content)

    if _WRAP_LATEX:
        instance._content, math = wrap_math(instance._content, ignore_within)
    else:
        math = True if _MATH_REGEX.search(instance._content) else False

    # The user initially set typogrify to be True, but since it would clash
    # with math, we set it to False. This means that the default reader will
    # not call typogrify, so it is called here, where we are able to control
    # logic for it ignore math if necessary
    if _TYPOGRIFY:
        # Tell typogrify to ignore the tags that math has been wrapped in
        # also, typogrify must always ignore mml (math) tags
        ignore_tags = [_WRAP_LATEX,'math'] if _WRAP_LATEX else ['math']

        # Exact copy of the logic as found in the default reader
        from typogrify.filters import typogrify
        instance._content = typogrify(instance._content, ignore_tags)
        instance.metadata['title'] = typogrify(instance.metadata['title'], ignore_tags)

    if math:
        if _MATHJAX_SETTINGS['auto_insert']:
            # Mathjax script added to content automatically. Now it
            # does not need to be explicitly added to the template
            instance._content += _MATHJAX_SCRIPT.format(**_MATHJAX_SETTINGS)
        else:
            # Place the burden on ensuring mathjax script is available to
            # browser on the template designer (see README for more details)
            instance.mathjax = True

        # The summary needs special care because math math cannot just be cut
        # off
        summary = process_summary(instance, ignore_within)
        if summary != None:
            instance._summary = summary
开发者ID:jeffskinnerbox,项目名称:pelican-plugins,代码行数:47,代码来源:math.py


示例9: markup

def markup(text):
    """
    Mark up plain text into fancy HTML.
    """
    return typogrify(
        markdown(text,
                 lazy_ol=False,
                 output_format='html5',
                 extensions=['abbr', 'codehilite', 'fenced_code', 'sane_lists',
                             'smart_strong']))
开发者ID:patrickbeeson,项目名称:camino-bakery-website,代码行数:10,代码来源:models.py


示例10: process_content

def process_content(instance):
    """Processes content, with logic to ensure that typogrify does not clash
    with latex.

    In addition, mathjax script is inserted at the end of the content thereby
    making it independent of the template
    """

    if not instance._content:
        return

    ignore_within = ignore_content(instance._content)

    if _WRAP_TAG:
        instance._content, latex = wrap_latex(instance._content, ignore_within)
    else:
        latex = True if _LATEX_REGEX.search(instance._content) else False

    # The user initially set typogrify to be True, but since it would clash
    # with latex, we set it to False. This means that the default reader will
    # not call typogrify, so it is called here, where we are able to control
    # logic for it ignore latex if necessary
    if _TYPOGRIFY:
        # Tell typogrify to ignore the tags that latex has been wrapped in
        # also, typogrify must always ignore mml (math) tags
        ignore_tags = [_WRAP_TAG,'math'] if _WRAP_TAG else ['math']

        # Exact copy of the logic as found in the default reader
        from typogrify.filters import typogrify
        instance._content = typogrify(instance._content, ignore_tags)
        instance.metadata['title'] = typogrify(instance.metadata['title'], ignore_tags)

    if latex:
        # Mathjax script added to the end of article. Now it does not need to
        # be explicitly added to the template
        instance._content += _MATHJAX_SCRIPT.format(**_MATHJAX_SETTINGS)

        # The summary needs special care because latex math cannot just be cut
        # off
        summary = process_summary(instance, ignore_within)
        if summary != None:
            instance._summary = summary
开发者ID:bobslee,项目名称:pelican-plugins,代码行数:42,代码来源:latex.py


示例11: present_story_so_far

    def present_story_so_far(self):
        if not self.state.messages:
            self.state = self.state.render_situation()

        story_text = u'\n\n'.join(m for m in self.state.messages
                                  if m is not None and m.strip())

        logger.debug("#### The Story:\n%s", story_text)
        md_extensions = self.plot.config['markdown']['extensions']
        story_text = markdown.markdown(story_text, extensions=md_extensions)
        story = typogrify(story_text)

        return story
开发者ID:eykd,项目名称:storyline,代码行数:13,代码来源:turns.py


示例12: read_file

def read_file(filename, fmt=None, settings=None):
    """Return a reader object using the given format."""
    base, ext = os.path.splitext(os.path.basename(filename))
    if not fmt:
        fmt = ext[1:]

    if fmt not in _EXTENSIONS:
        raise TypeError('Pelican does not know how to parse %s' % filename)

    reader = _EXTENSIONS[fmt](settings)
    settings_key = '%s_EXTENSIONS' % fmt.upper()

    if settings and settings_key in settings:
        reader.extensions = settings[settings_key]

    if not reader.enabled:
        raise ValueError("Missing dependencies for %s" % fmt)

    content, metadata = reader.read(filename)

    # eventually filter the content with typogrify if asked so
    if settings and settings.get('TYPOGRIFY'):
        from typogrify.filters import typogrify
        content = typogrify(content)
        metadata['title'] = typogrify(metadata['title'])

    filename_metadata = settings and settings.get('FILENAME_METADATA')
    if filename_metadata:
        match = re.match(filename_metadata, base)
        if match:
            # .items() for py3k compat.
            for k, v in match.groupdict().items():
                if k not in metadata:
                    k = k.lower()  # metadata must be lowercase
                    metadata[k] = reader.process_metadata(k, v)

    return content, metadata
开发者ID:hailang,项目名称:pelican,代码行数:37,代码来源:readers.py


示例13: render_files

def render_files(settings, template, context={}):
    env = Environment(loader=FileSystemLoader(os.path.dirname(__file__)))
    if 'context' in settings:
        settings['context'].update(context)
    else:
        settings['context'] = context 
    full_context = {k.upper(): v for k, v in settings['context'].items()}
    try:
        used_template = template if template else settings['template']
    except KeyError:
        print('Some error shit') # TODO: Logging
        sys.exit()
    html_output = env.get_template(settings['template']).render(**full_context)
    text_output = fromstring(html_output).text_content()
    typo_output = typogrify(html_output)
    if settings.get('html_output'):
        with open(settings['html_output'], 'w') as html:
            html.write(typo_output)
        if settings.get('text_output'):
            with open(settings['text_output'], 'w') as text:
                text.write(text_output)
    else:
        print(text_output)
开发者ID:gunshor,项目名称:newschimp,代码行数:23,代码来源:renderer.py


示例14: render_files

def render_files(settings, template, context={}):
    try:
        used_template = template if template else settings['template']
    except KeyError:
        LOGGER.error('No template defined')
        sys.exit()
    env = Environment(loader=FileSystemLoader(os.getcwd()))
    if 'context' in settings:
        settings['context'].update(context)
    else:
        settings['context'] = context
    full_context = {k.upper(): v for k, v in settings['context'].items()}
    html_output = env.get_template(settings['template']).render(**full_context)
    text_output = fromstring(html_output).text_content()
    typo_output = typogrify(html_output)
    output_files = settings['output']
    if output_files.get('html'):
        with open(output_files.get('html'), 'w') as html:
            html.write(typo_output)
        if output_files.get('text'):
            with open(output_files.get('text'), 'w') as text:
                text.write(text_output)
    else:
        print(text_output)
开发者ID:sputnikus,项目名称:newschimp,代码行数:24,代码来源:renderer.py


示例15: typogrify

def typogrify(s):
    return jinja2_filters.typogrify(s)
开发者ID:harryh,项目名称:xkcd2,代码行数:2,代码来源:xkcd2.py


示例16: typeset

def typeset(md):
    html = markdown(md, extensions=MARKDOWN_EXTRAS)
    typogrified_html = typogrify(html)
    return typogrified_html
开发者ID:chrilisch,项目名称:datahackermd,代码行数:4,代码来源:site.py


示例17: markup

def markup(text):
	"""
	Use this filter to convert Markdown syntax used in the text to HTML on the template.
	"""
	return typogrify(markdown.markdown(text, lazy_ol=False, output_format='html5', extensions=['abbr', 'codehilite', 'fenced_code', 'sane_lists', 'smart_strong']))
开发者ID:patrickbeeson,项目名称:camino-bakery-website,代码行数:5,代码来源:markup.py


示例18: convert_to_html

 def convert_to_html(content):
     return typogrify(markdown.markdown(content, extensions=['extra', 'codehilite']))
开发者ID:pombredanne,项目名称:engineer,代码行数:2,代码来源:models.py


示例19: run

def run(content):
    return typogrify(content)
开发者ID:amtinits,项目名称:blog,代码行数:2,代码来源:typogrify_filter.py


示例20: process_text

    def process_text(self, input_text):
        #t = make_safe(typogrify)
        #return t(input_text)
		return typogrify(input_text)
开发者ID:Laurian,项目名称:dexy-filters,代码行数:4,代码来源:Typogrify.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tzlocal.get_localzone函数代码示例发布时间:2022-05-27
下一篇:
Python typing.TextIO类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap