Metadata-Version: 2.5
Name: palestine
Version: 0.2.2
Summary: A Python DOM and server-side HTML rendering library
Project-URL: Homepage, https://github.com/u84u/palestine
Project-URL: Documentation, https://github.com/u84u/palestine#readme
Project-URL: Repository, https://github.com/u84u/palestine
Project-URL: Issues, https://github.com/u84u/palestine/issues
Author: u84u
License: MIT
Keywords: dom,html,rendering,server-side,ssr,template
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.14
Description-Content-Type: text/markdown

# Palestine

A Python library for building and rendering HTML using a DOM and component model.

## Installation

```bash
pip install palestine
```

Requires Python 3.14+.

## Quick start

```python
from palestine import Document, Html, Body, Div, Text

doc = Document()
html = Html()
body = Body()
doc.append_child(html)
html.append_child(body)

page = Div(class_="container")
page.append_child(Text("Hello from Palestine"))
body.append_child(page)

print(doc)
```

Output:

```html
<!DOCTYPE html>
<html><body><div class="container">Hello from Palestine</div></body></html>
```

## What it looks like

### Build a DOM tree

```python
from palestine import Div, Text, Button

card = Div(class_="card")
card.append_child(Text("Title"))
card.append_child(Button(type="submit").append_child(Text("Click")))

# Move nodes between parents automatically
other = Div()
other.append_child(card)  # Detaches from previous parent
```

### Render HTML

```python
from palestine import Div, Text, RawText

# Text is escaped automatically
div = Div()
div.append_child(Text("<script>"))  # Renders as &lt;script&gt;

# RawText is for trusted markup
div.append_child(RawText("<svg>...</svg>"))  # Renders as-is
```

### Compose components

```python
from palestine import Div, H1, P, Text

def Card(title, content):
    card = Div(class_="card")
    card.append_child(H1().append_child(Text(title)))
    card.append_child(P().append_child(Text(content)))
    return card

page = Div()
page.append_child(Card("First", "Content here"))
page.append_child(Card("Second", "More content"))
```

### Parse and manipulate HTML

```python
from palestine import parse_html

doc = parse_html('<div class="box"><p>Hello</p></div>')
div = doc.query_selector(".box")
div.append_child(parse_html("<span>World</span>"))
```

### Templates

```python
from palestine import Template

tmpl = Template("<h1>{{ title }}</h1><p>{{ content }}</p>")
html = tmpl.render(title="My Page", content="Hello world")
```

### Forms and validation

```python
from palestine import FormBuilder, FormValidator, Required, Email

form = FormBuilder(action="/submit", method="post")
form.add_text("name", "Name", required=True)
form.add_email("email", "Email", required=True)
form.add_submit("Register")

validator = FormValidator({
    "name": [Required()],
    "email": [Required(), Email()],
})
errors = validator.validate({"name": "", "email": "invalid"})
```

## Features

- **DOM primitives**: Node, Element, Text, RawText, Comment, Document
- **HTML elements**: All standard HTML5 elements
- **Rendering**: HTML serialization, pretty printing, minification, streaming
- **Parsing**: HTML to DOM conversion
- **Templates**: Variable substitution and control flow
- **Components**: Reusable UI composition
- **Forms**: Form building and validation
- **Security**: HTML sanitization, escaping, URL validation
- **VDOM**: Virtual DOM with diff/patch

## Architecture

Palestine is built around a mutable DOM tree:

```
Node
  ├── Element (tag, attributes, children)
  ├── Text (escaped content)
  ├── RawText (trusted markup)
  ├── Comment
  └── Document (root node)
```

Components are functions that compose elements. The renderer serializes the tree to HTML.

## Status

Early-stage project. The core DOM, rendering, and template engine are functional and tested.

The parser is built on Python's `html.parser` and does not implement the full WHATWG HTML parsing algorithm. It handles common cases but may differ from browser parsing on malformed input.

The API may change between versions.

## License

MIT
