samyak152002 commited on
Commit
d368b7f
·
verified ·
1 Parent(s): 70b2638

Create text_utils.py

Browse files
Files changed (1) hide show
  1. text_utils.py +17 -0
text_utils.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # text_utils.py
2
+ from markdown_it import MarkdownIt
3
+ from mdit_plain.renderer import RendererPlain
4
+
5
+ def convert_markdown_to_plain_text(markdown_text: str) -> str:
6
+ """
7
+ Converts a Markdown string to plain text.
8
+ """
9
+ if not markdown_text:
10
+ return ""
11
+ try:
12
+ parser = MarkdownIt(renderer_cls=RendererPlain)
13
+ plain_text = parser.render(markdown_text)
14
+ return plain_text
15
+ except Exception as e:
16
+ print(f"Error converting Markdown to plain text: {e}")
17
+ return markdown_text