diff --git a/src/pipecat/processors/text/markdown_remover.py b/src/pipecat/processors/text/markdown_remover.py index eb42ce8ee..57b0d0147 100644 --- a/src/pipecat/processors/text/markdown_remover.py +++ b/src/pipecat/processors/text/markdown_remover.py @@ -7,6 +7,7 @@ import re from markdown import Markdown +from pydantic import BaseModel from pipecat.frames.frames import Frame, TextFrame from pipecat.processors.frame_processor import FrameDirection, FrameProcessor @@ -20,9 +21,13 @@ class MarkdownRemovalProcessor(FrameProcessor): asterisks and table formatting. """ - def __init__(self, **kwargs): + class InputParams(BaseModel): + speak_code: bool = True + + def __init__(self, params: InputParams = InputParams(), **kwargs): super().__init__(**kwargs) self._md = Markdown() + self._params = params async def process_frame(self, frame: Frame, direction: FrameDirection): await super().process_frame(frame, direction) @@ -37,6 +42,9 @@ class MarkdownRemovalProcessor(FrameProcessor): # Replace newlines with spaces only when there's no text before or after markdown_string = re.sub(r"^\s*\n", "", markdown_string, flags=re.MULTILINE) + # Remove backticks from inline code, but not from code blocks + markdown_string = re.sub(r"(?.*?", "", html, flags=re.DOTALL) + # Remove HTML tags text = re.sub("<[^<]+?>", "", html)