Metadata-Version: 2.4
Name: mdimg
Version: 0.1.2
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Text Processing :: Markup :: Markdown
Classifier: Typing :: Typed
License-File: LICENSE-MIT
License-File: LICENSE-APACHE
Summary: Functional interface for substituting image syntax in Markdown across its many forms
Keywords: markdown,image,html,map,parser
License-Expression: MIT OR Apache-2.0
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Repository, https://github.com/niller-g/mdimg

# mdimg

mdimg provides a functional interface for substituting image syntax in Markdown across its
many different forms. E.g. `![alt](url)` and `<img src="url" alt="alt">`.

The markdown parser is [pulldown-cmark](https://pulldown-cmark.github.io/pulldown-cmark/) and
simply re-exports its functionality and configuration options.

## Example

```python
import mdimg

# Normal markdown image syntax
text1 = "Before ![alt](file.png) after"

# A tag split across lines inside blockquotes `>`
text2 = '> <img\n> src="a.png">'

# A reference image whose URL is defined elsewhere
text3 = "![b][ref]\n\n[ref]: b.png"

# Code blocks are not treated as images
text4 = "`![not an image](c.png)`"

text = "\n\n".join([text1, text2, text3, text4])
output = mdimg.map_images(text, lambda image: f"[image: alt={image.alt or ''} url={image.url}]")
assert output == (
    "Before [image: alt=alt url=file.png] after\n\n"
    "> [image: alt= url=a.png]\n\n"
    "[image: alt=b url=b.png]\n\n"
    "[ref]: b.png\n\n"
    "`![not an image](c.png)`"
)
```

### GitHub Flavored Markdown

```python
import mdimg

text = "| col |\n| --- |\n| ![alt](file.png) |"
output = mdimg.map_images(text, lambda image: image.url or "", markdown=mdimg.MarkdownOptions.GFM)
assert output == "| col |\n| --- |\n| file.png |"
```

### Identity mapping

```python
import mdimg

text = "![alt](file.png)"
output = mdimg.map_images(text, lambda image: image.raw)
assert output == text
```

