def convert(self, text): # Determine body self.md.reset() self.document_extensions = self._get_document_extensions(text) self._apply_extensions() body = self.md.convert(text) + '\n' # Determine title if hasattr(self.md, 'Meta') and 'title' in self.md.Meta: title = str.join(' ', self.md.Meta['title']) else: title = '' # Determine stylesheet css_class = None if 'markdown.extensions.codehilite' in self.extensions: config = self.extension_configs.get('markdown.extensions.codehilite', {}) css_class = config.get('css_class', 'codehilite') stylesheet = common.get_pygments_stylesheet('.%s' % css_class) elif 'pymdownx.highlight' in self.extensions: config = self.extension_configs.get('pymdownx.highlight', {}) css_class = config.get('css_class', 'highlight') stylesheet = common.get_pygments_stylesheet('.%s' % css_class) else: stylesheet = '' return ConvertedMarkdown(body, title, stylesheet)
def convert(self, text): parts = self._publish_parts(text, source_path=self.filename, writer_name='html5', settings_overrides=self.overrides) # Determine head head = parts['head'] # Determine body body = parts['html_body'] # Determine title title = parts['title'] # Determine stylesheet origstyle = parts['stylesheet'] # Cut off <style> and </style> tags stylestart = '<style type="text/css">' stylesheet = '' if stylestart in origstyle: stylesheet = origstyle[origstyle.find(stylestart) + 25:origstyle.rfind('</style>')] stylesheet += common.get_pygments_stylesheet('.code') return ConvertedReStructuredText(head, body, title, stylesheet)
def get_stylesheet(self, text=''): has_codehilite = False for extension in self.extensions: if extension.endswith('codehilite'): has_codehilite = True if has_codehilite: return common.get_pygments_stylesheet('.codehilite') return ''
def get_stylesheet(self, text=''): origstyle = self.publish_parts(text)['stylesheet'] # Cut off <style> and </style> tags stylestart = '<style type="text/css">' stylesheet = '' if stylestart in origstyle: stylesheet = origstyle[origstyle.find(stylestart)+25:origstyle.rfind('</style>')] return stylesheet + common.get_pygments_stylesheet('.code')
def convert(self, text): # Determine body self.md.reset() self.document_extensions = self._get_document_extensions(text) self._apply_extensions() body = self.md.convert(text) + '\n' # Determine title if hasattr(self.md, 'Meta') and 'title' in self.md.Meta: title = str.join(' ', self.md.Meta['title']) else: title = '' # Determine stylesheet if any(extension.endswith('codehilite') for extension in self.extensions): stylesheet = common.get_pygments_stylesheet('.codehilite') else: stylesheet = '' return ConvertedMarkdown(body, title, stylesheet)
def convert(self, text): parts = self._publish_parts( text, source_path=self.filename, writer_name="html", settings_overrides=self.overrides ) # Determine head head = parts["head"] # Determine body body = parts["html_body"] # Determine title title = parts["title"] # Determine stylesheet origstyle = parts["stylesheet"] # Cut off <style> and </style> tags stylestart = '<style type="text/css">' stylesheet = "" if stylestart in origstyle: stylesheet = origstyle[origstyle.find(stylestart) + 25 : origstyle.rfind("</style>")] stylesheet += common.get_pygments_stylesheet(".code") return ConvertedReStructuredText(head, body, title, stylesheet)