msticpy.vis.code_view module

Display code with with highlighting.

msticpy.vis.code_view.display_html(code: str, language: str, style: str = 'stata-dark', full: bool = True, display_handle: bool = False) IPython.display.DisplayHandle | None

Display pygments-formatted code.

Parameters:
  • code (str) – Input code as string.

  • language (str) – The language name or alias.

  • style (str, optional) – The pygments style to use, by default “stata-dark”

  • full (bool, optional) – By default this function will return a complete HTML document, to only return the formatted code snippet (minus styles), set full=False.

  • display_handle (bool, optional) – If True, will return an IPython DisplayHandle for the display object created.

Returns:

Handle to the IPython display object.

Return type:

Optional[DisplayHandle]

See also

to_html

msticpy.vis.code_view.list_pygments_styles() List[str]

Return list of pygments styles available.

Returns:

The list of pygments style names.

Return type:

List[str]

msticpy.vis.code_view.to_html(code: str, language: str, style: str = 'default', full: bool = True) str

Return Pygments-highlighted code for specified language.

Parameters:
  • code (str) – Input code as string.

  • language (str) – The language name or alias.

  • style (str, optional) – The pygments style to use, by default “default”

  • full (bool, optional) – By default this function will return a complete HTML document, to only return the formatted code snippet (minus styles), set full=False.

Returns:

HTML document with pygments formatting.

Return type:

str