示例#1
0
    def blog_mod_render_items(self, blog, items):
        if self.markdown_highlight_style:
            from pygments.style import Style
            from pygments.styles import get_style_by_name
            from pygments.formatters import HtmlFormatter

            # User-defined custom style takes precedence
            try:
                with tmp_sys_path(self.config.get('command_dir', "")):
                    mod = import_module(self.markdown_highlight_style)
            except ImportError:
                mdstyle = None
            else:
                mdstyle = first_subclass(mod, Style)

            # Try for built-in style if no custom style
            if not mdstyle:
                mdstyle = get_style_by_name(self.markdown_highlight_style)

            # Generate CSS with selector for markdown codehilite extension
            css = HtmlFormatter(style=mdstyle).get_style_defs(
                arg=".codehilite")
            if not css.endswith(os.linesep):
                css = "{}{}".format(css, os.linesep)
            csspath = blog.metadata['highlight_stylesheet_url']
            if csspath.startswith('/'):
                csspath = csspath[1:]
            items.append((encode(css, blog.metadata['charset']), csspath))

        return items
示例#2
0
 def blog_mod_render_items(self, blog, items):
     if self.markdown_highlight_style:
         from pygments.style import Style
         from pygments.styles import get_style_by_name
         from pygments.formatters import HtmlFormatter
         
         # User-defined custom style takes precedence
         try:
             with tmp_sys_path(self.config.get('command_dir', "")):
                 mod = import_module(self.markdown_highlight_style)
         except ImportError:
             mdstyle = None
         else:
             mdstyle = first_subclass(mod, Style)
         
         # Try for built-in style if no custom style
         if not mdstyle:
             mdstyle = get_style_by_name(self.markdown_highlight_style)
         
         # Generate CSS with selector for markdown codehilite extension
         css = HtmlFormatter(style=mdstyle).get_style_defs(arg=".codehilite")
         if not css.endswith(os.linesep):
             css = "{}{}".format(css, os.linesep)
         csspath = blog.metadata['highlight_stylesheet_url']
         if csspath.startswith('/'):
             csspath = csspath[1:]
         items.append((encode(css, blog.metadata['charset']), csspath))
     
     return items
示例#3
0
文件: sub.py 项目: pdonis/simpleblog
def load_subs(subs, subtype, subdir, err, subcls):
    with tmp_sys_path(subdir):
        for name in subs:
            yield load_submodule(subtype, subdir, name, err, subcls)
示例#4
0
文件: sub.py 项目: pdonis/simpleblog
def load_sub(name, subtype, subdir, err, subcls):
    with tmp_sys_path(subdir):
        return load_submodule(subtype, subdir, name, err, subcls)
示例#5
0
文件: sub.py 项目: pdonis/simpleblog3
def load_subs(subs, subtype, subdir, err, subcls):
    with tmp_sys_path(subdir):
        for name in subs:
            yield load_submodule(subtype, subdir, name, err, subcls)
示例#6
0
文件: sub.py 项目: pdonis/simpleblog3
def load_sub(name, subtype, subdir, err, subcls):
    with tmp_sys_path(subdir):
        return load_submodule(subtype, subdir, name, err, subcls)