Skip to content
Back to top
View this page
Edit this page

# Code Results

Typification of the code results. Results of this type are rendered in the code.html template. For highlighting the code passages, Pygments is used.

final class searx.result_types.code.Code(title: str = '', content: str = '', img_src: str = '', iframe_src: str = '', audio_src: str = '', thumbnail: str = '', publishedDate: datetime | None = None, pubdate: str = '', length: timedelta | None = None, views: str = '', author: str = '', metadata: str = '', priority: Literal['', 'high', 'low']='', engines: set[str] = <factory>, open_group: bool = False, close_group: bool = False, positions: list[int] = <factory>, score: float = 0, category: str = '', *, template: str = 'code.html', url: str | None = None, engine: str | None = '', parsed_url: ParseResult | None = None, repository: str | None = None, codelines: list[tuple[int, str]]=<factory>, hl_lines: set[int] = <factory>, code_language: str = '<guess>', filename: str | None = None, strip_new_lines: bool = True, strip_whitespace: bool = False)

  Bases: `MainResult`

  Result type suitable for displaying code passages.

  repository: str | None

    A link related to a repository related to the result.

  codelines: list[tuple[int, str]]

    A list of two digit tuples where the first item is the line number and the second item is the code line.

  hl_lines: set[int]

    A list of line numbers to highlight.

  code_language: str

    Pygment’s short name of the lexer, e.g. `text` for the `pygments.lexers.special.TextLexer`. For a list of available languages consult: Pygments languages. If the language is not in this list, a `ValueError` is raised.

    The default is `<guess>` which has a special meaning;

    - If `Code.filename` is set, Pygment’s factory method `pygments.lexers.guess_lexer_for_filename` is used to determine the language of the `codelines`.

    - else Pygment’s `pygments.lexers.guess_lexer` factory is used.

    In case the language can’t be detected, the fallback is `text`.

  filename: str | None

    Optional file name, can help to `<guess>` the language of the code (in case of ambiguous short code examples). If `Code.title` is not set, its default is the filename.

  strip_new_lines: bool

    Strip leading and trailing newlines for each returned fragment (default: `True`). Single file might return multiple code fragments.

  strip_whitespace: bool

    Strip all leading and trailing whitespace for each returned fragment (default: `False`). Single file might return multiple code fragments. Enabling this might break code indentation.

  HTML(**options) → str

    Rendered HTML, additional options are accepted, for more details have a look at HtmlFormatter.