Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'input_encoding': 'utf-8',
'exit_status_level': 2,
'embed_stylesheet': False
}
user_params = self.settings.get('DOCUTILS_SETTINGS', None)
if user_params:
extra_params.update(user_params)
pub = docutils.core.Publisher(
source_class=RstReader.FileInput,
destination_class=docutils.io.StringOutput)
pub.set_components('standalone', 'restructuredtext', 'html')
pub.writer.translator_class = PelicanHTMLTranslator
pub.process_programmatic_settings(None, extra_params, None)
pub.set_source(source=contents)
pub.publish(enable_exit_status=True)
return pub
def _get_publisher(self, source):
extra_params = {'initial_header_level': '2',
'syntax_highlight': 'short',
'input_encoding': 'utf-8',
'exit_status_level': 2,
'embed_stylesheet': False}
user_params = self.settings.get('DOCUTILS_SETTINGS')
if user_params:
extra_params.update(user_params)
pub = docutils.core.Publisher(
source_class=self.FileInput,
destination_class=docutils.io.StringOutput)
pub.set_components('standalone', 'restructuredtext', 'html')
pub.writer.translator_class = PelicanHTMLTranslator
pub.process_programmatic_settings(None, extra_params, None)
pub.set_source(source=source)
pub.publish(enable_exit_status=True)
return pub
def register():
directives.register_directive('itemscope', ItemScopeDirective)
roles.register_canonical_role('itemprop', itemprop_role)
PelicanHTMLTranslator.visit_ItemProp = as_method(visit_ItemProp)
PelicanHTMLTranslator.depart_ItemProp = as_method(depart_ItemProp)
PelicanHTMLTranslator.visit_ItemScope = as_method(visit_ItemScope)
PelicanHTMLTranslator.depart_ItemScope = as_method(depart_ItemScope)
# handle compact parameter
# TODO: find a cleaner way to handle this case
PelicanHTMLTranslator.visit_paragraph = as_method(visit_paragraph)
# Fetch settings on initialized
initialized.connect(set_vocabulary)
def _generate_html(data):
extra_params = {'initial_header_level': '2',
'syntax_highlight': 'short',
'input_encoding': 'utf-8',
'exit_status_level': 2,
'compact_p': False,
'embed_stylesheet': False}
pub = docutils.core.Publisher(
source_class=docutils.io.StringInput,
destination_class=docutils.io.StringOutput)
pub.set_components('standalone', 'restructuredtext', 'html')
pub.writer.translator_class = PelicanHTMLTranslator
pub.process_programmatic_settings(None, extra_params, None)
pub.set_source(source=data, source_path=None)
pub.publish(enable_exit_status=True)
return pub.writer.parts['body']
def as_method(func):
return six.create_unbound_method(func, PelicanHTMLTranslator)
def _get_publisher(self, source, source_file_path):
# This is a slightly modified copy of `RstReader._get_publisher`
extra_params = {'initial_header_level': '4',
'syntax_highlight': 'short',
'input_encoding': 'utf-8',
'exit_status_level': 2,
'embed_stylesheet': False}
user_params = self.settings.get('DOCUTILS_SETTINGS')
if user_params:
extra_params.update(user_params)
pub = docutils.core.Publisher(
source_class=docutils.io.StringInput,
destination_class=docutils.io.StringOutput)
pub.set_components('standalone', 'restructuredtext', 'html')
pub.writer.translator_class = PelicanHTMLTranslator
pub.process_programmatic_settings(None, extra_params, None)
pub.set_source(source=source, source_path=source_file_path)
pub.publish(enable_exit_status=True)
return pub