MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / format_markdown_output

Function format_markdown_output

demo_unirec.py:155–179  ·  view source on GitHub ↗

Format markdown text for display. This function handles: - HTML tables (pass through as-is for Gradio Markdown rendering) - LaTeX formulas (already in proper format) - Basic markdown formatting

(markdown_text)

Source from the content-addressed store, hash-verified

153
154
155def format_markdown_output(markdown_text):
156 """Format markdown text for display.
157
158 This function handles:
159 - HTML tables (pass through as-is for Gradio Markdown rendering)
160 - LaTeX formulas (already in proper format)
161 - Basic markdown formatting
162 """
163 if not markdown_text:
164 return '_Waiting for recognition results..._'
165 if '<table>' in markdown_text:
166 markdown_text = markdown_converter._handle_table(markdown_text)
167 if '\\(' in markdown_text or '\\[' in markdown_text:
168 # extract the formula
169 formula_pattern = r'\n\n\\\[.*?\\\]\n\n'
170 # print(re.findall(formula_pattern, markdown_text, flags=re.DOTALL))
171 # markdown_text = re.sub(formula_pattern, markdown_converter._handle_formula, markdown_text, flags=re.DOTALL)
172 for formula in re.findall(formula_pattern, markdown_text, flags=re.DOTALL):
173 markdown_text = markdown_text.replace(formula, markdown_converter._handle_formula(formula))
174 if '\\(' in markdown_text:
175 markdown_text = markdown_text.replace('\\(', '$')
176 markdown_text = markdown_text.replace('\\)', '$')
177 # Return the markdown text as-is
178 # Gradio's Markdown component will handle the rendering
179 return markdown_text
180
181def create_demo() -> gr.Blocks:
182

Callers 1

stream_recognize_imageFunction · 0.85

Calls 2

_handle_tableMethod · 0.80
_handle_formulaMethod · 0.80

Tested by

no test coverage detected