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
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
def __init__(cls, name, bases, attrs): super(BlogExtensionMeta, cls).__init__(name, bases, attrs) # Auto-detect entry, page, and blog mixins in this class's module thismod = sys.modules[__name__] clsmod = sys.modules[cls.__module__] for etype in ('Entry', 'Page', 'Blog'): mixin_klass = getattr(thismod, '%sMixin' % etype) ext_mixin = first_subclass(clsmod, mixin_klass) if ext_mixin: setattr(cls, '%s_mixin' % etype.lower(), ext_mixin)
def load_submodule(subtype, subdir, name, err, subcls): name = name.replace('-', '_') mod = None if subdir: # User-supplied module takes precedence try: mod = import_module(name) except ImportError: pass if mod is None: try: mod = import_module("simpleblog.{0}s.{1}".format(subtype, name)) except ImportError: raise err("{0} {1} not found!".format(subtype, name)) klass = first_subclass(mod, subcls) if not klass: raise err("no {0} in {1} module!".format(subtype, name)) return mod, klass