Skip to main content

code

Themes

from dara.components.common.code import Themes

class Themes(str, Enum)

Code component available themes enum

Code

from dara.components.common.code import Code

class Code(ContentComponent)

Code

A Code component is used to display/highlight a section of code in your document. It accepts a block of code as it's first argument and can also accept an optional parameter of language to specify the type of highlighting to use. By default the language is set to python (available languages can be found here: https://highlightjs.org/static/demo/)

A code component rendered with code as a string and language:


from dara.components.common import Code

Code(code='def some_func():\n pass', language='py')

You can set a theme for the code component different than the one set for the app, for example you can have the app using the default light theme, but code in dark mode:


from dara.components.common import Code

Code(code='def some_func():\n pass', theme=Code.Themes.DARK)

Arguments:

  • code: The code to be formatted as a string
  • theme: Defines the theme to be used by the component, can be either 'light' or 'dark', if unset it will infer this from the app's set theme
  • language: The language to use for code highlighting

Attributes

  • code: Union[str, NonDataVariable]
  • theme: Optional[Themes]
  • language: str
  • Themes: ClassVar[ThemesType]