Exemplo n.º 1
0
def markdown(
        source: str = None,
        source_path: str = None,
        preserve_lines: bool = False,
        font_size: float = None,
        **kwargs
):
    """
    Renders the specified source string or source file using markdown and 
    adds the resulting HTML to the notebook display.

    :param source:
        A markdown formatted string.
    :param source_path:
        A file containing markdown text.
    :param preserve_lines:
        If True, all line breaks will be treated as hard breaks. Use this
        for pre-formatted markdown text where newlines should be retained
        during rendering.
    :param font_size:
        Specifies a relative font size adjustment. The default value is 1.0,
        which preserves the inherited font size values. Set it to a value
        below 1.0 for smaller font-size rendering and greater than 1.0 for
        larger font size rendering.
    :param kwargs:
        Any variable replacements to make within the string using Jinja2
        templating syntax.
    """
    r = _get_report()

    result = render_texts.markdown(
        source=source,
        source_path=source_path,
        preserve_lines=preserve_lines,
        font_size=font_size,
        **kwargs
    )
    r.library_includes += result['library_includes']

    r.append_body(result['body'])
    r.stdout_interceptor.write_source(
        '{}\n'.format(textwrap.dedent(result['rendered']))
    )
Exemplo n.º 2
0
def markdown(source: str = None,
             source_path: str = None,
             preserve_lines: bool = False,
             font_size: float = None,
             **kwargs):
    """
    Renders the specified source string or source file using markdown and 
    adds the resulting HTML to the notebook display.

    :param source:
        A markdown formatted string.
    :param source_path:
        A file containing markdown text.
    :param preserve_lines:
        If True, all line breaks will be treated as hard breaks. Use this
        for pre-formatted markdown text where newlines should be retained
        during rendering.
    :param font_size:
        Specifies a relative font size adjustment. The default value is 1.0,
        which preserves the inherited font size values. Set it to a value
        below 1.0 for smaller font-size rendering and greater than 1.0 for
        larger font size rendering.
    :param kwargs:
        Any variable replacements to make within the string using Jinja2
        templating syntax.
    """
    r = _get_report()

    result = render_texts.markdown(source=source,
                                   source_path=source_path,
                                   preserve_lines=preserve_lines,
                                   font_size=font_size,
                                   **kwargs)
    r.library_includes += result['library_includes']

    r.append_body(result['body'])
    r.stdout_interceptor.write_source('{}\n'.format(
        textwrap.dedent(result['rendered'])))
Exemplo n.º 3
0
def markdown(source: str = None, source_path: str = None, **kwargs):
    """
    Renders the specified source string or source file using markdown and 
    adds the resulting HTML to the notebook display.

    :param source:
        A markdown formatted string
    :param source_path:
        A file containing markdown text
    :param kwargs:
        Any variable replacements to make within the string using Jinja2
        templating syntax.
    """

    r = _get_report()

    result = render_texts.markdown(
        source=source,
        source_path=source_path,
        **kwargs
    )
    r.library_includes += result['library_includes']

    r.append_body(result['body'])
Exemplo n.º 4
0
 def test_markdown_unfinished_latex(self):
     """Should not render latex that has no closing $$."""
     source = 'Hello world $$ x_b = 12'
     result = texts.markdown(source)
     self.assertTrue(0 < result['body'].find('$$'))
Exemplo n.º 5
0
 def test_markdown_unavailable(self, *args):
     """
     Should raise an import error is the markdown package isn't available.
     """
     with self.assertRaises(ImportError):
         texts.markdown('this is a test')
Exemplo n.º 6
0
 def test_markdown_unfinished_latex(self):
     """Should not render latex that has no closing $$."""
     source = 'Hello world $$ x_b = 12'
     result = texts.markdown(source)
     self.assertTrue(0 < result['body'].find('$$'))
Exemplo n.º 7
0
 def test_markdown_unavailable(self, *args):
     """
     Should raise an import error is the markdown package isn't available.
     """
     with self.assertRaises(ImportError):
         texts.markdown('this is a test')