markdown_text_filter

Markdown text filter for removing Markdown formatting from text.

This module provides a text filter that converts Markdown content to plain text while preserving structure and handling special cases like code blocks and tables.

class pipecat.utils.text.markdown_text_filter.MarkdownTextFilter(params: InputParams | None = None, **kwargs)[source]

Bases: BaseTextFilter

Text filter that removes Markdown formatting from text content.

Converts Markdown to plain text while preserving the overall structure, including leading and trailing spaces. Handles special cases like asterisks and table formatting. Supports selective filtering of code blocks and tables based on configuration.

class InputParams(*, enable_text_filter: bool | None = True, filter_code: bool | None = False, filter_tables: bool | None = False)[source]

Bases: BaseModel

Configuration parameters for Markdown text filtering.

Parameters:
  • enable_text_filter – Whether to apply Markdown filtering. Defaults to True.

  • filter_code – Whether to remove code blocks from the text. Defaults to False.

  • filter_tables – Whether to remove table content from the text. Defaults to False.

enable_text_filter: bool | None
filter_code: bool | None
filter_tables: bool | None
__init__(params: InputParams | None = None, **kwargs)[source]

Initialize the Markdown text filter.

Parameters:
  • params – Configuration parameters for filtering behavior.

  • **kwargs – Additional keyword arguments passed to parent class.

async update_settings(settings: Mapping[str, Any])[source]

Update the filter’s configuration settings.

Parameters:

settings – Dictionary of setting names to values for configuration.

async filter(text: str) str[source]

Apply Markdown filtering transformations to the input text.

Parameters:

text – The input text containing Markdown formatting to be filtered.

Returns:

The filtered text with Markdown formatting removed or converted.

async handle_interruption()[source]

Handle interruption events in the processing pipeline.

Resets the filter state and clears any tracking variables for code blocks and tables.

async reset_interruption()[source]

Reset the filter state after an interruption has been handled.

Clears the interrupted flag to restore normal operation.

remove_tables(text: str) str[source]

Remove HTML tables from the input text.

Handles cases where both start and end tags are in the same input, as well as tables that span multiple text chunks.

Parameters:

text – The text containing HTML tables to remove.

Returns:

The text with tables removed.