Metadata-Version: 2.4
Name: spellbook-engine
Version: 0.1.0.post1
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Text Processing :: Markup :: Markdown
Classifier: Typing :: Typed
License-File: LICENSE
Summary: The SpellBlock syntax engine, for Python.
Keywords: markdown,parser,spellbook,django
License-Expression: AGPL-3.0-only
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Repository, https://git.stormdevelopments.ca/official-public/spellbook-engine

# spellbook-engine for Python

Python glue for [spellbook-engine](https://git.stormdevelopments.ca/official-public/spellbook-engine),
the SpellBlock syntax engine. It holds no logic of its own: every answer is the
Rust engine's, handed to Python. The syntax is in the engine's `SPEC.md`.

```python
import spellbook_engine

nodes = spellbook_engine.parse('Intro.\n\n{~ alert type="info" ~}\nBody.\n{~~}\n')

intro, alert, rest = nodes
assert intro == "Intro.\n\n"            # markdown comes back as str
assert alert.name == "alert"
assert alert.get("type") == "info"
assert alert.body.source == "\nBody.\n"

try:
    spellbook_engine.parse("{~ a ~}\n{~ b ~}\n{~~}\n{~~}")
except spellbook_engine.SpellbookSyntaxError as error:
    assert (error.kind, error.line, error.column) == ("NestedBlock", 2, 1)
```

## What you get

- `parse(source)` returns a list: `str` for markdown, `Block` for a block.
- `Block` has `name`, `line`, `attrs`, `body`, and the shared readings `get()`,
  `has_flag()`, `classes()` and `id()`.
- `Body` has `source`, the body as written, and `nodes`, the same body split. A
  block inside a body is always self-closing.
- `SpellbookSyntaxError` is a `ValueError` with `kind`, `line` and `column`.

## Development

From the repository root, `make python` builds the module into a virtual
environment and runs these tests. `make python-dist` builds the wheel and the
source archive into `python/dist`, installs each alone and runs the tests
against it.

The wheel is for Linux on x86-64, glibc 2.17 or newer. Anywhere else, pip builds
from the source archive, which needs a Rust toolchain.

## License

AGPL-3.0. The full text is in the repository's `LICENSE` file.

