formatting module¶
Classes for content formatting.
See vectorbtpro.utils.knowledge for the toy dataset.
format_html function¶
Convert Markdown to HTML using ToHTML.
resolve_formatter function¶
Resolve a subclass or an instance of ContentFormatter.
The following values are supported:
- "plain" (PlainFormatter): Prints the raw output
- "ipython" (IPythonFormatter): Renders an unformatted text in a notebook environment
- "ipython_markdown" (IPythonMarkdownFormatter): Renders a Markdown in a notebook environment
- "ipython_html" (IPythonHTMLFormatter): Renders an HTML in a notebook environment
- "ipython_auto": Decides between using "ipython_html" or "plain" depending on the environment
- "html" (HTMLFileFormatter): Writes a static HTML page and displays it in the browser
- A subclass or an instance of ContentFormatter
to_html function¶
Convert Markdown to HTML using ToHTML.
to_markdown function¶
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
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- Cacheable.get_ca_setup
- Chainable.chain
- Chainable.pipe
- Configured.config
- Configured.copy
- Configured.equals
- Configured.get_writeable_attrs
- Configured.prettify
- Configured.rec_state
- Configured.replace
- Configured.resolve_merge_kwargs
- Configured.update_config
- HasSettings.get_path_setting
- HasSettings.get_path_settings
- HasSettings.get_setting
- HasSettings.get_settings
- HasSettings.has_path_setting
- HasSettings.has_path_settings
- HasSettings.has_setting
- HasSettings.has_settings
- HasSettings.reset_settings
- HasSettings.resolve_setting
- HasSettings.resolve_settings_paths
- HasSettings.set_settings
- Pickleable.decode_config
- Pickleable.decode_config_node
- Pickleable.dumps
- Pickleable.encode_config
- Pickleable.encode_config_node
- Pickleable.file_exists
- Pickleable.getsize
- Pickleable.load
- Pickleable.loads
- Pickleable.modify_state
- Pickleable.resolve_file_path
- Pickleable.save
- Prettified.pprint
Subclasses
append method¶
Append new content to buffer and update.
append_once method¶
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¶
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¶
Update for the last time and close the stream.
flush method¶
Flush buffer and final line.
flush_output class property¶
Whether to flush output.
format_line method¶
Format line.
in_code_block class property¶
Whether currently in a code block.
initialize method¶
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¶
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
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- Cacheable.get_ca_setup
- Chainable.chain
- Chainable.pipe
- Configured.config
- Configured.copy
- Configured.equals
- Configured.get_writeable_attrs
- Configured.prettify
- Configured.rec_state
- Configured.replace
- Configured.resolve_merge_kwargs
- Configured.update_config
- HasSettings.get_path_setting
- HasSettings.get_path_settings
- HasSettings.get_setting
- HasSettings.get_settings
- HasSettings.has_path_setting
- HasSettings.has_path_settings
- HasSettings.has_setting
- HasSettings.has_settings
- HasSettings.reset_settings
- HasSettings.resolve_setting
- HasSettings.resolve_settings_paths
- HasSettings.set_settings
- Pickleable.decode_config
- Pickleable.decode_config_node
- Pickleable.dumps
- Pickleable.encode_config
- Pickleable.encode_config_node
- Pickleable.file_exists
- Pickleable.getsize
- Pickleable.load
- Pickleable.loads
- Pickleable.modify_state
- Pickleable.resolve_file_path
- Pickleable.save
- Prettified.pprint
body_extras class property¶
Extras for <body>.
format_html method¶
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
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- Cacheable.get_ca_setup
- Chainable.chain
- Chainable.pipe
- Configured.copy
- Configured.equals
- Configured.get_writeable_attrs
- Configured.prettify
- Configured.replace
- Configured.resolve_merge_kwargs
- Configured.update_config
- ContentFormatter.append
- ContentFormatter.append_once
- ContentFormatter.buffer
- ContentFormatter.buffer_output
- ContentFormatter.buffer_update
- ContentFormatter.close_output
- ContentFormatter.code_block_indent
- ContentFormatter.config
- ContentFormatter.content
- ContentFormatter.current_line
- ContentFormatter.finalize
- ContentFormatter.flush
- ContentFormatter.flush_output
- ContentFormatter.format_line
- ContentFormatter.in_code_block
- ContentFormatter.initialize
- ContentFormatter.last_update
- ContentFormatter.lines
- ContentFormatter.minimal_format
- ContentFormatter.output_to
- ContentFormatter.rec_state
- ContentFormatter.template_context
- ContentFormatter.update_interval
- HasSettings.get_path_setting
- HasSettings.get_path_settings
- HasSettings.get_setting
- HasSettings.get_settings
- HasSettings.has_path_setting
- HasSettings.has_path_settings
- HasSettings.has_setting
- HasSettings.has_settings
- HasSettings.reset_settings
- HasSettings.resolve_setting
- HasSettings.resolve_settings_paths
- HasSettings.set_settings
- Pickleable.decode_config
- Pickleable.decode_config_node
- Pickleable.dumps
- Pickleable.encode_config
- Pickleable.encode_config_node
- Pickleable.file_exists
- Pickleable.getsize
- Pickleable.load
- Pickleable.loads
- Pickleable.modify_state
- Pickleable.resolve_file_path
- Pickleable.save
- Prettified.pprint
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¶
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¶
Update the HTML file with newly-updated content.
IPythonFormatter class¶
Class for formatting plain content in IPython.
For defaults, see formatting.formatter_configs.ipython in knowledge.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- Cacheable.get_ca_setup
- Chainable.chain
- Chainable.pipe
- Configured.copy
- Configured.equals
- Configured.get_writeable_attrs
- Configured.prettify
- Configured.replace
- Configured.resolve_merge_kwargs
- Configured.update_config
- ContentFormatter.append
- ContentFormatter.append_once
- ContentFormatter.buffer
- ContentFormatter.buffer_output
- ContentFormatter.buffer_update
- ContentFormatter.close_output
- ContentFormatter.code_block_indent
- ContentFormatter.config
- ContentFormatter.content
- ContentFormatter.current_line
- ContentFormatter.finalize
- ContentFormatter.flush
- ContentFormatter.flush_output
- ContentFormatter.format_line
- ContentFormatter.in_code_block
- ContentFormatter.initialize
- ContentFormatter.last_update
- ContentFormatter.lines
- ContentFormatter.minimal_format
- ContentFormatter.output_to
- ContentFormatter.rec_state
- ContentFormatter.template_context
- ContentFormatter.update
- ContentFormatter.update_interval
- HasSettings.get_path_setting
- HasSettings.get_path_settings
- HasSettings.get_setting
- HasSettings.get_settings
- HasSettings.has_path_setting
- HasSettings.has_path_settings
- HasSettings.has_setting
- HasSettings.has_settings
- HasSettings.reset_settings
- HasSettings.resolve_setting
- HasSettings.resolve_settings_paths
- HasSettings.set_settings
- Pickleable.decode_config
- Pickleable.decode_config_node
- Pickleable.dumps
- Pickleable.encode_config
- Pickleable.encode_config_node
- Pickleable.file_exists
- Pickleable.getsize
- Pickleable.load
- Pickleable.loads
- Pickleable.modify_state
- Pickleable.resolve_file_path
- Pickleable.save
- Prettified.pprint
Subclasses
display_handle class property¶
Display handle.
update_display method¶
Update display with content.
IPythonHTMLFormatter class¶
Class for formatting HTML content in IPython.
For defaults, see formatting.formatter_configs.ipython_html in knowledge.
Superclasses
- Base
- Cacheable
- Chainable
- Comparable
- Configured
- ContentFormatter
- HasSettings
- IPythonFormatter
- Pickleable
- Prettified
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- Cacheable.get_ca_setup
- Chainable.chain
- Chainable.pipe
- Configured.copy
- Configured.equals
- Configured.get_writeable_attrs
- Configured.prettify
- Configured.replace
- Configured.resolve_merge_kwargs
- Configured.update_config
- ContentFormatter.append
- ContentFormatter.append_once
- ContentFormatter.buffer_update
- ContentFormatter.finalize
- ContentFormatter.flush
- ContentFormatter.format_line
- HasSettings.get_path_setting
- HasSettings.get_path_settings
- HasSettings.get_setting
- HasSettings.get_settings
- HasSettings.has_path_setting
- HasSettings.has_path_settings
- HasSettings.has_setting
- HasSettings.has_settings
- HasSettings.reset_settings
- HasSettings.resolve_setting
- HasSettings.resolve_settings_paths
- HasSettings.set_settings
- IPythonFormatter.buffer
- IPythonFormatter.buffer_output
- IPythonFormatter.close_output
- IPythonFormatter.code_block_indent
- IPythonFormatter.config
- IPythonFormatter.content
- IPythonFormatter.current_line
- IPythonFormatter.display_handle
- IPythonFormatter.flush_output
- IPythonFormatter.in_code_block
- IPythonFormatter.initialize
- IPythonFormatter.last_update
- IPythonFormatter.lines
- IPythonFormatter.minimal_format
- IPythonFormatter.output_to
- IPythonFormatter.rec_state
- IPythonFormatter.template_context
- IPythonFormatter.update
- IPythonFormatter.update_display
- IPythonFormatter.update_interval
- Pickleable.decode_config
- Pickleable.decode_config_node
- Pickleable.dumps
- Pickleable.encode_config
- Pickleable.encode_config_node
- Pickleable.file_exists
- Pickleable.getsize
- Pickleable.load
- Pickleable.loads
- Pickleable.modify_state
- Pickleable.resolve_file_path
- Pickleable.save
- Prettified.pprint
to_html_kwargs class property¶
Keyword arguments passed to to_html.
to_markdown_kwargs class property¶
Keyword arguments passed to to_markdown.
IPythonMarkdownFormatter class¶
Class for formatting Markdown content in IPython.
For defaults, see formatting.formatter_configs.ipython_markdown in knowledge.
Superclasses
- Base
- Cacheable
- Chainable
- Comparable
- Configured
- ContentFormatter
- HasSettings
- IPythonFormatter
- Pickleable
- Prettified
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- Cacheable.get_ca_setup
- Chainable.chain
- Chainable.pipe
- Configured.copy
- Configured.equals
- Configured.get_writeable_attrs
- Configured.prettify
- Configured.replace
- Configured.resolve_merge_kwargs
- Configured.update_config
- ContentFormatter.append
- ContentFormatter.append_once
- ContentFormatter.buffer_update
- ContentFormatter.finalize
- ContentFormatter.flush
- ContentFormatter.format_line
- HasSettings.get_path_setting
- HasSettings.get_path_settings
- HasSettings.get_setting
- HasSettings.get_settings
- HasSettings.has_path_setting
- HasSettings.has_path_settings
- HasSettings.has_setting
- HasSettings.has_settings
- HasSettings.reset_settings
- HasSettings.resolve_setting
- HasSettings.resolve_settings_paths
- HasSettings.set_settings
- IPythonFormatter.buffer
- IPythonFormatter.buffer_output
- IPythonFormatter.close_output
- IPythonFormatter.code_block_indent
- IPythonFormatter.config
- IPythonFormatter.content
- IPythonFormatter.current_line
- IPythonFormatter.display_handle
- IPythonFormatter.flush_output
- IPythonFormatter.in_code_block
- IPythonFormatter.initialize
- IPythonFormatter.last_update
- IPythonFormatter.lines
- IPythonFormatter.minimal_format
- IPythonFormatter.output_to
- IPythonFormatter.rec_state
- IPythonFormatter.template_context
- IPythonFormatter.update
- IPythonFormatter.update_display
- IPythonFormatter.update_interval
- Pickleable.decode_config
- Pickleable.decode_config_node
- Pickleable.dumps
- Pickleable.encode_config
- Pickleable.encode_config_node
- Pickleable.file_exists
- Pickleable.getsize
- Pickleable.load
- Pickleable.loads
- Pickleable.modify_state
- Pickleable.resolve_file_path
- Pickleable.save
- Prettified.pprint
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
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- Cacheable.get_ca_setup
- Chainable.chain
- Chainable.pipe
- Configured.copy
- Configured.equals
- Configured.get_writeable_attrs
- Configured.prettify
- Configured.replace
- Configured.resolve_merge_kwargs
- Configured.update_config
- ContentFormatter.append
- ContentFormatter.append_once
- ContentFormatter.buffer
- ContentFormatter.buffer_output
- ContentFormatter.buffer_update
- ContentFormatter.close_output
- ContentFormatter.code_block_indent
- ContentFormatter.config
- ContentFormatter.content
- ContentFormatter.current_line
- ContentFormatter.finalize
- ContentFormatter.flush
- ContentFormatter.flush_output
- ContentFormatter.format_line
- ContentFormatter.in_code_block
- ContentFormatter.initialize
- ContentFormatter.last_update
- ContentFormatter.lines
- ContentFormatter.minimal_format
- ContentFormatter.output_to
- ContentFormatter.rec_state
- ContentFormatter.template_context
- ContentFormatter.update
- ContentFormatter.update_interval
- HasSettings.get_path_setting
- HasSettings.get_path_settings
- HasSettings.get_setting
- HasSettings.get_settings
- HasSettings.has_path_setting
- HasSettings.has_path_settings
- HasSettings.has_setting
- HasSettings.has_settings
- HasSettings.reset_settings
- HasSettings.resolve_setting
- HasSettings.resolve_settings_paths
- HasSettings.set_settings
- Pickleable.decode_config
- Pickleable.decode_config_node
- Pickleable.dumps
- Pickleable.encode_config
- Pickleable.encode_config_node
- Pickleable.file_exists
- Pickleable.getsize
- Pickleable.load
- Pickleable.loads
- Pickleable.modify_state
- Pickleable.resolve_file_path
- Pickleable.save
- Prettified.pprint
ToHTML class¶
Class to convert Markdown to HTML.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- Cacheable.get_ca_setup
- Chainable.chain
- Chainable.pipe
- Configured.config
- Configured.copy
- Configured.equals
- Configured.get_writeable_attrs
- Configured.prettify
- Configured.rec_state
- Configured.replace
- Configured.resolve_merge_kwargs
- Configured.update_config
- HasSettings.get_path_setting
- HasSettings.get_path_settings
- HasSettings.get_setting
- HasSettings.get_settings
- HasSettings.has_path_setting
- HasSettings.has_path_settings
- HasSettings.has_setting
- HasSettings.has_settings
- HasSettings.reset_settings
- HasSettings.resolve_setting
- HasSettings.resolve_settings_paths
- HasSettings.set_settings
- Pickleable.decode_config
- Pickleable.decode_config_node
- Pickleable.dumps
- Pickleable.encode_config
- Pickleable.encode_config_node
- Pickleable.file_exists
- Pickleable.getsize
- Pickleable.load
- Pickleable.loads
- Pickleable.modify_state
- Pickleable.resolve_file_path
- Pickleable.save
- Prettified.pprint
make_links class property¶
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¶
Convert Markdown to HTML.
ToMarkdown class¶
Class to convert text to Markdown.
Superclasses
Inherited members
- Base.chat
- Base.find_api
- Base.find_assets
- Base.find_docs
- Base.find_examples
- Base.find_messages
- Cacheable.get_ca_setup
- Chainable.chain
- Chainable.pipe
- Configured.config
- Configured.copy
- Configured.equals
- Configured.get_writeable_attrs
- Configured.prettify
- Configured.rec_state
- Configured.replace
- Configured.resolve_merge_kwargs
- Configured.update_config
- HasSettings.get_path_setting
- HasSettings.get_path_settings
- HasSettings.get_setting
- HasSettings.get_settings
- HasSettings.has_path_setting
- HasSettings.has_path_settings
- HasSettings.has_setting
- HasSettings.has_settings
- HasSettings.reset_settings
- HasSettings.resolve_setting
- HasSettings.resolve_settings_paths
- HasSettings.set_settings
- Pickleable.decode_config
- Pickleable.decode_config_node
- Pickleable.dumps
- Pickleable.encode_config
- Pickleable.encode_config_node
- Pickleable.file_exists
- Pickleable.getsize
- Pickleable.load
- Pickleable.loads
- Pickleable.modify_state
- Pickleable.resolve_file_path
- Pickleable.save
- Prettified.pprint
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¶
Convert text to Markdown.