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)
| 153 | |
| 154 | |
| 155 | def 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 | |
| 181 | def create_demo() -> gr.Blocks: |
| 182 |
no test coverage detected