Skip to main content

Python library for easily interacting with trained machine learning models

Project description


tags: [gradio-custom-component, Markdown] title: gradio_somarkdown short_description: A custom Gradio component that renders Markdown with KaTeX math, SMILES chemical structures, mhchem equations, and syntax-highlighted code blocks. colorFrom: blue colorTo: yellow sdk: gradio pinned: false app_file: space.py

gradio_somarkdown

Static Badge

A custom Gradio component that replaces gr.Markdown with the SoMarkDown renderer — adding KaTeX math, SMILES chemical structures, mhchem chemical equations, syntax-highlighted code blocks, and Table of Contents generation.

Installation

pip install gradio_somarkdown

Usage

import gradio as gr
from gradio_somarkdown import SoMarkDown

example = r"""
## Math
$$ E = mc^2 $$  Inline: $e^{i\pi} + 1 = 0$

## Chemical Structure
$$ \smiles{CC(=O)Oc1ccccc1C(=O)O} $$

## Chemistry (mhchem)
$$ \ce{CO2 + C -> 2 CO} $$

## Code
```python
def fib(n):
    return n if n <= 1 else fib(n-1) + fib(n-2)

"""

with gr.Blocks() as demo: SoMarkDown(value=example, katex={"throwOnError": False})

demo.launch()


## `SoMarkDown`

### Initialization

| name | type | default | description |
|:-----|:-----|:--------|:------------|
| `value` | `str \| Callable \| None` | `None` | SoMarkdown content to render. Accepts a callable for dynamic values. |
| `linkify` | `bool` | `True` | Auto-convert URL-like text to links. |
| `typographer` | `bool` | `True` | Enable smart quotes and language-neutral typographic replacements. |
| `katex` | `dict \| None` | `None` | KaTeX options (e.g. `{"throwOnError": False}`). `trust` and `strict` are always forced to `True`/`False`. |
| `smiles` | `dict \| None` | `None` | SMILES renderer options (e.g. `{"disableColors": False, "width": 150, "height": 150}`). |
| `img_desc_enabled` | `bool` | `True` | Show image descriptions below images. |
| `rtl` | `bool` | `False` | Right-to-left text direction. |
| `height` | `int \| str \| None` | `None` | Fixed height; content scrolls when it overflows. |
| `max_height` | `int \| str \| None` | `None` | Maximum height; shrinks to content when shorter. |
| `min_height` | `int \| str \| None` | `None` | Minimum height; expands to content when taller. |
| `container` | `bool` | `False` | Wrap in a Gradio Block container. |
| `padding` | `bool` | `False` | Apply `--block-padding` CSS variable. |

Backward-compatibility parameters from `gr.Markdown` (`sanitize_html`, `header_links`, `line_breaks`, `buttons`, `latex_delimiters`) are accepted but ignored.

### Events

| name | description |
|:-----|:------------|
| `change` | Triggered when the value changes (user input or function update). |
| `copy` | Triggered when the user copies content. Carries copied text via `gradio.CopyData`. |

### User function

```python
def predict(value: str | None) -> str | None:
    return value

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gradio_somarkdown-0.0.1.tar.gz (4.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gradio_somarkdown-0.0.1-py3-none-any.whl (4.7 MB view details)

Uploaded Python 3

File details

Details for the file gradio_somarkdown-0.0.1.tar.gz.

File metadata

  • Download URL: gradio_somarkdown-0.0.1.tar.gz
  • Upload date:
  • Size: 4.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for gradio_somarkdown-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8282a31382bad99eca05690bba41c3ae34b9eb93ad103aa74ff9cfa87fb3911e
MD5 c34e9a62015e79a2ca712788b4b1e1cc
BLAKE2b-256 599664ad7d78f2158e7bde9a3937b1747db11d7ecb5d739c82044b5448e941c8

See more details on using hashes here.

File details

Details for the file gradio_somarkdown-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for gradio_somarkdown-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b0eb610e2730ad26f4d432ad39584ea70798a60be7f7122ded5b79ce5c5b0c86
MD5 441f0bbf618d8f4dc119d419d018f592
BLAKE2b-256 e14510617dd5346c219c34aa3d9e6386f98562fc2dac144dc5c032ce4d28c4bc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page