Skip to main content

No project description provided

Project description

dinject

dinject (document injection) is a CLI tool for executing code blocks in Markdown documents then injecting the results.

What?

Say you have a project documented in Markdown:

The `script` property returns the block's `lines` as a single script.

For example:

```python
from dinject.types import Block

block = Block(lang="foo", lines=["line 1\n", "line 2\n"])
print(block.script)
```

If you wanted to include the example's output then you could append a text block, like this:

The `script` property returns the block's `lines` as a single script.

For example:

```python
from dinject.types import Block

block = Block(lang="foo", lines=["line 1\n", "line 2\n"])
print(block.script)
```

```text
line 1
line 2
```

...but if the demonstrated function's response ever changes then you'll need to remember to update the example.

dinject automates the execution of embedded code. Rather than append the example yourself, append a <!--dinject--> tag instead:

The `script` property returns the block's `lines` as a single script.

For example:

```python
from dinject.types import Block

block = Block(lang="foo", lines=["line 1\n", "line 2\n"])
print(block.script)
```

<!--dinject-->

To execute the embedded code and inject the result, run dinject YOUR_DOC.md.

The result will be:

The `script` property returns the block's `lines` as a single script.

For example:

```python
from dinject.types import Block

block = Block(lang="foo", lines=["line 1\n", "line 2\n"])
print(block.script)
```

<!--dinject as=markdown host=shell range=start-->

```text
line 1
line 2
```

<!--dinject range=end-->

Installation

dinject requires Python 3.8 or later:

pip install dinject

Live example

Here's a Python code block, with the result injected automatically by running dinject README.md:

from dinject.types import Block

block = Block(lang="foo", lines=["line 1\n", "line 2\n"])
print(block.script)
line 1
line 2

👋 Hello!

Hello! I'm Cariad Eccleston and I'm an independent/freelance software engineer. If my work has value to you, please consider sponsoring.

If you ever raise a bug, request a feature or ask a question then mention that you're a sponsor and I'll respond as a priority. Thank you!

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

dinject-1.0.3-py3-none-any.whl (11.7 kB view hashes)

Uploaded Python 3

Supported by

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