Skip to content

formatting module

Classes for content formatting.

See vectorbtpro.utils.knowledge for the toy dataset.


format_html function

format_html(
    **kwargs
)

Convert Markdown to HTML using ToHTML.


resolve_formatter function

resolve_formatter(
    formatter
)

Resolve a subclass or an instance of ContentFormatter.

The following values are supported:


to_html function

to_html(
    text,
    **kwargs
)

Convert Markdown to HTML using ToHTML.


to_markdown function

to_markdown(
    text,
    **kwargs
)

Convert text to Markdown using ToMarkdown.


ContentFormatter class

ContentFormatter(
    output_to=None,
    flush_output=None,
    buffer_output=None,
    close_output=None,
    update_interval=None,
    minimal_format=None,
    template_context=None,
    **kwargs
)

Class for formatting content.

For defaults, see knowledge.formatting.formatter_config in knowledge.

Superclasses

Inherited members

Subclasses


append method

ContentFormatter.append(
    new_content,
    final=False
)

Append new content to buffer and update.


append_once method

ContentFormatter.append_once(
    content
)

Append final content and finalize.


buffer class property

List of strings in the buffer.


buffer_output class property

Whether to buffer output.


buffer_update method

ContentFormatter.buffer_update()

Update based on buffer content.


close_output class property

Whether to close output.


code_block_indent class property

Indentation of the code block.


content class property

Content.


current_line class property

List of strings representing the current line.


finalize method

ContentFormatter.finalize(
    update=True
)

Update for the last time and close the stream.


flush method

ContentFormatter.flush(
    final=False
)

Flush buffer and final line.


flush_output class property

Whether to flush output.


format_line method

ContentFormatter.format_line(
    line
)

Format line.


in_code_block class property

Whether currently in a code block.


initialize method

ContentFormatter.initialize()

Initialize.


last_update class property

Last update time.


lines class property

List of lines.


minimal_format class property

Whether input is minimally-formatted.


output_to class property

Redirect output to a file or stream.


template_context class property

Context used to substitute templates.


update method

ContentFormatter.update(
    final=False
)

Update content.


update_interval class property

Update interval (in seconds).


FormatHTML class

FormatHTML(
    html_template=None,
    style_extras=None,
    head_extras=None,
    body_extras=None,
    invert_colors=None,
    invert_colors_style=None,
    auto_scroll=None,
    auto_scroll_body=None,
    show_spinner=None,
    spinner_style=None,
    spinner_body=None,
    use_pygments=None,
    pygments_kwargs=None,
    template_context=None,
    **kwargs
)

Class to format HTML.

If use_pygments is True, uses Pygments package for code highlighting. Arguments in pygments_kwargs are then passed to pygments.formatters.HtmlFormatter.

Use style_extras to inject additional CSS rules outside the predefined ones. Use head_extras to inject additional HTML elements into the <head> section, such as meta tags, links to external stylesheets, or scripts. Use body_extras to inject JavaScript files or inline scripts at the end of the <body>. All of these arguments can be lists.

HTML template is a template that can use all the arguments except those related to pygments. It can be either a custom template, or string or function that will become one.

Superclasses

Inherited members


body_extras class property

Extras for <body>.


format_html method

FormatHTML.format_html(
    title='',
    html_metadata='',
    html_content='',
    **kwargs
)

Format HTML.


head_extras class property

Extras for <head>.


html_template class property

HTML template.


style_extras class property

Extras for <style>.


template_context class property

Context used to substitute templates.


HTMLFileFormatter class

HTMLFileFormatter(
    *args,
    page_title='',
    refresh_page=None,
    dir_path=None,
    mkdir_kwargs=None,
    temp_files=None,
    file_prefix_len=None,
    file_suffix_len=None,
    auto_scroll=None,
    show_spinner=None,
    open_browser=None,
    to_markdown_kwargs=None,
    to_html_kwargs=None,
    format_html_kwargs=None,
    **kwargs
)

Class for formatting static HTML files.

For defaults, see formatting.formatter_configs.html in knowledge.

Superclasses

Inherited members


auto_scroll class property

Whether to scroll automatically while refreshing.


dir_path class property

Path to the directory.


file_handle class property

File handle.


file_prefix_len class property

Number of chars of a truncated title as a prefix.


file_suffix_len class property

Number of chars of a random hash as a suffix.


format_html_content method

HTMLFileFormatter.format_html_content(
    html_content,
    final=False
)

Format HTML content.


format_html_kwargs class property

Keyword arguments passed to format_html.


mkdir_kwargs class property

Keyword arguments passed to check_mkdir.


open_browser class property

Whether to open the default browser.


page_title class property

Page title.


refresh_page class property

Whether to refresh the HTML page.


show_spinner class property

Whether to show spinner while refreshing.


temp_files class property

Whether to save as temporary files

Otherwise, will save under HTMLFileFormatter.dir_path.


to_html_kwargs class property

Keyword arguments passed to to_html.


to_markdown_kwargs class property

Keyword arguments passed to to_markdown.


update method

HTMLFileFormatter.update(
    final=False
)

Update the HTML file with newly-updated content.


IPythonFormatter class

IPythonFormatter(
    *args,
    **kwargs
)

Class for formatting plain content in IPython.

For defaults, see formatting.formatter_configs.ipython in knowledge.

Superclasses

Inherited members

Subclasses


display_handle class property

Display handle.


update_display method

IPythonFormatter.update_display()

Update display with content.


IPythonHTMLFormatter class

IPythonHTMLFormatter(
    *args,
    to_markdown_kwargs=None,
    to_html_kwargs=None,
    **kwargs
)

Class for formatting HTML content in IPython.

For defaults, see formatting.formatter_configs.ipython_html in knowledge.

Superclasses

Inherited members


to_html_kwargs class property

Keyword arguments passed to to_html.


to_markdown_kwargs class property

Keyword arguments passed to to_markdown.


IPythonMarkdownFormatter class

IPythonMarkdownFormatter(
    *args,
    to_markdown_kwargs=None,
    **kwargs
)

Class for formatting Markdown content in IPython.

For defaults, see formatting.formatter_configs.ipython_markdown in knowledge.

Superclasses

Inherited members


to_markdown_kwargs class property

Keyword arguments passed to to_markdown.


PlainFormatter class

PlainFormatter(
    output_to=None,
    flush_output=None,
    buffer_output=None,
    close_output=None,
    update_interval=None,
    minimal_format=None,
    template_context=None,
    **kwargs
)

Class for formatting plain content.

For defaults, see formatting.formatter_configs.plain in knowledge.

Superclasses

Inherited members


ToHTML class

ToHTML(
    resolve_extensions=None,
    make_links=None,
    **markdown_kwargs
)

Class to convert Markdown to HTML.

Superclasses

Inherited members


Whether to detect raw URLs in HTML text (p and span elements only) and convert them to links.


markdown_kwargs class property

Keyword arguments passed to markdown.markdown.


resolve_extensions class property

Whether to resolve Markdown extensions.

Uses pymdownx extensions over native extensions if installed.


to_html method

ToHTML.to_html(
    markdown
)

Convert Markdown to HTML.


ToMarkdown class

ToMarkdown(
    remove_code_title=None,
    even_indentation=None,
    newline_before_list=None,
    **kwargs
)

Class to convert text to Markdown.

Superclasses

Inherited members


even_indentation class property

Whether to make leading spaces even.

For example, 3 leading spaces become 4.


newline_before_list class property

Whether to add a new line before a list.


remove_code_title class property

Whether to remove title attribute from a code block and puts it above it.


to_markdown method

ToMarkdown.to_markdown(
    text
)

Convert text to Markdown.