Metadata-Version: 2.4
Name: QMarkdownWidget
Version: 1.2.1
Summary: A Python library providing modern Markdown and LaTeX widgets for PyQt/PySide.
Author-email: KercyDing <dkx215417@gmail.com>
Project-URL: Homepage, https://github.com/KercyDing/QMarkdownWidget
Project-URL: Documentation, https://github.com/KercyDing/QMarkdownWidget#readme
Project-URL: Repository, https://github.com/KercyDing/QMarkdownWidget.git
Project-URL: Issues, https://github.com/KercyDing/QMarkdownWidget/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: Markup
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: markdown-it-py>=2.0.0
Requires-Dist: linkify-it-py>=2.0.0
Requires-Dist: qtpy>=2.0.0
Provides-Extra: pyqt6
Requires-Dist: PyQt6; extra == "pyqt6"
Requires-Dist: PyQt6-WebEngine; extra == "pyqt6"
Provides-Extra: pyside6
Requires-Dist: PySide6; extra == "pyside6"
Requires-Dist: PySide6-WebEngine; extra == "pyside6"
Dynamic: license-file

# QMarkdownWidget

[![PyPI version](https://img.shields.io/pypi/v/QMarkdownWidget)](https://pypi.org/project/QMarkdownWidget/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

`QMarkdownWidget` is a Python library that provides modern and feature-rich widgets for rendering Markdown and LaTeX in PyQt and PySide applications. It offers two distinct components tailored for different use cases.

## Features

- **`QMLabel`**: A lightweight and efficient widget based on `QLabel` for rendering simple Markdown. It's fast and ideal for displaying basic formatted text without the overhead of a full web engine.
- **`QMView`**: A powerful widget based on `QWebEngineView` for displaying complex Markdown documents. 
- They offer:
    - **Full GFM (GitHub-Flavored Markdown) support**.
    - **High-quality LaTeX rendering** via MathJax(**only QMView supports**).
    - **Advanced auto-sizing** to precisely fit its content.
    - **Full styling capabilities** using both QSS and internal CSS.

## Installation

You can install `QMarkdownWidget` from PyPI:
```bash
pip install QMarkdownWidget
```

## Usage

Here are some examples of how to use the widgets.

### Basic `QMLabel` Usage

`QMLabel` is as simple to use as a standard `QLabel`.

```python
import sys
from qtpy.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget
from QMarkdownWidget import QMLabel

app = QApplication(sys.argv)
window = QMainWindow()
central_widget = QWidget()
layout = QVBoxLayout(central_widget)

label_text = """
# This is a QMLabel
- Renders **basic** Markdown.
- Very *lightweight*.
"""
label = QMLabel(label_text)
layout.addWidget(label)

window.setCentralWidget(central_widget)
window.show()
sys.exit(app.exec())
```

### Basic `QMView` Usage

`QMView` can handle much more complex content, including LaTeX and code blocks.

```python
import sys
from qtpy.QtWidgets import QApplication, QMainWindow
from QMarkdownWidget import QMView

app = QApplication(sys.argv)
window = QMainWindow()

view_text = r"""
# This is a QMView
It supports **Markdown** and LaTeX, like $E=mc^2$
"""
view = QMView(view_text)
window.setCentralWidget(view)
window.show()
sys.exit(app.exec())
```

### Advanced: `QMView` Auto-Sizing

The `setAutoSize` method gives you powerful control over the widget's layout.

```python
import sys
from qtpy.QtWidgets import QApplication, QMainWindow
from QMarkdownWidget import QMView

# 1. Basic auto-sizing: shrinks to fit content
view1 = QMView("Shrinks to fit.")
view1.setAutoSize(True)

# 2. Width-constrained: content wraps at 300px, height adjusts
view2 = QMView("This long text will wrap...")
view2.setAutoSize(True, max_width=300)

# 3. Height-constrained: content is clipped at 150px with a scrollbar
view3 = QMView("This tall content will be scrollable...")
view3.setAutoSize(True, max_height=150)

...
```

## API Reference

### `QMLabel`
A lightweight widget for simple Markdown.

- `__init__(self, text: str = "", parent=None)`
  - Initializes the label with optional Markdown text.

- `setMarkdown(self, text: str)`
  - Renders and displays a new Markdown string.

### `QMView`
A full-featured widget for complex Markdown, code, and LaTeX.

- `__init__(self, text: str = "", parent=None)`
  - Initializes the view with optional Markdown text.

- `setMarkdown(self, text: str)`
  - Renders and displays a new Markdown string.

- `setAutoSize(self, enabled: bool, max_width: int = -1, max_height: int = -1)`
  - Enables or disables auto-sizing.
  - **`enabled`**: If `True`, the widget shrinks to fit its content. If `False`, it expands to fill available space.
  - **`max_width`**: Constrains the content's width, forcing text to wrap. The widget's height will adjust accordingly.
  - **`max_height`**: Constrains the widget's height. If content is taller, a vertical scrollbar will appear.

- `setHtmlStyle(self, style: str)`
  - Injects a custom CSS string to style the internal HTML content. This is useful for changing fonts, colors, etc., beyond what QSS can target.

## Contributing

Contributions, issues, and feature requests are welcome! Please feel free to open an issue or submit a pull request.

## License

This project is licensed under the MIT License. 
