Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using the filter without quarto #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# quarto-d2 1.2.0

## NEW FUNCTIONALITY

- Allow using the filter as a simple pandoc filter. This allows using the filter with other
document formats such as Rmarkdown.

# quarto-d2 1.1.0

## NEW FUNCTIONALITY
Expand Down
71 changes: 46 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,6 @@ Main features:
This extension was inspired by
[`ram02z/d2-filter`](https://github.com/ram02z/d2-filter).

## Installation

### Prerequisites

Ensure that you have [D2](https://d2lang.com/tour/install) installed on
your system.

### Install

Run the following command to add this extension to your current project:

``` bash
quarto add data-intuitive/quarto-d2
```

This will install the extension under the `_extensions` subdirectory. If
you’re using version control, you will want to check in this directory.

## Example

<div>
Expand Down Expand Up @@ -89,11 +71,39 @@ user -> network.portal.UI: access {

</div>

## Prerequisites

Ensure that you have [D2](https://d2lang.com/tour/install) installed on
your system.

## Usage

To use the d2 filter, add the d2 filter to your quarto document. Next,
add the `.d2` class to any code blocks containing D2 diagram code. Here
is a basic example:
The filter allows rendering D2 diagrams directly within your markdown
documents.

### Plain pandoc

If you are using plain pandoc, you can use the `d2` filter by specifying
it on the command line:

``` bash
pandoc --lua-filter d2.lua ...
```

### Quarto

Install this filter as an extension with:

``` bash
quarto add data-intuitive/quarto-d2
```

This will install the extension under the `_extensions` subdirectory. If
you’re using version control, you will want to check in this directory.

By adding d2 to the list of filters in the YAML headers, you can use the
`.d2` code block to render D2 diagrams directly within your markdown
documents.

```` markdown
---
Expand All @@ -107,11 +117,17 @@ x -> y
```
````

With this setup, the `d2` filter will process any code blocks with the
`.d2` class, applying the attributes you specify.
### RMarkdown

Use `pandoc_args` to add the `d2` filter.

That’s it! Now you know how to use the `d2` filter to generate diagrams
in your quarto documents.
``` yaml
---
output:
html_document:
pandoc_args: ['--lua-filter=d2.lua']
---
```

## Attributes

Expand Down Expand Up @@ -223,3 +239,8 @@ y {
x -> y -> z
```
````

## License

This extension is distributed under the GPL-3 license, see file
[`LICENSE`](LICENSE) for details.
63 changes: 42 additions & 21 deletions README.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,6 @@ Main features:

This extension was inspired by [`ram02z/d2-filter`](https://github.com/ram02z/d2-filter).

## Installation

### Prerequisites

Ensure that you have [D2](https://d2lang.com/tour/install) installed on your system.

### Install

Run the following command to add this extension to your current project:

``` bash
quarto add data-intuitive/quarto-d2
```

This will install the extension under the `_extensions` subdirectory.
If you're using version control, you will want to check in this directory.



## Example

Expand Down Expand Up @@ -87,10 +69,37 @@ user -> network.portal.UI: access {
```


## Prerequisites

Ensure that you have [D2](https://d2lang.com/tour/install) installed on your system.


## Usage

To use the d2 filter, add the d2 filter to your quarto document. Next, add the `.d2` class to any code blocks containing D2 diagram code. Here is a basic example:
The filter allows rendering D2 diagrams directly within your markdown documents.

### Plain pandoc

If you are using plain pandoc, you can use the `d2` filter by specifying it on the command line:

```bash
pandoc --lua-filter d2.lua ...
```

### Quarto


Install this filter as an extension with:

``` bash
quarto add data-intuitive/quarto-d2
```

This will install the extension under the `_extensions` subdirectory.
If you're using version control, you will want to check in this directory.

By adding d2 to the list of filters in the YAML headers, you can use the `.d2` code block to
render D2 diagrams directly within your markdown documents.

````markdown
---
Expand All @@ -104,9 +113,17 @@ x -> y
```
````

With this setup, the `d2` filter will process any code blocks with the `.d2` class, applying the attributes you specify.
### RMarkdown

That's it! Now you know how to use the `d2` filter to generate diagrams in your quarto documents.
Use `pandoc_args` to add the `d2` filter.

```yaml
---
output:
html_document:
pandoc_args: ['--lua-filter=d2.lua']
---
```

## Attributes

Expand Down Expand Up @@ -191,3 +208,7 @@ y {
x -> y -> z
```
````

## License

This extension is distributed under the GPL-3 license, see file [`LICENSE`](LICENSE) for details.
6 changes: 6 additions & 0 deletions _extensions/d2/d2.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-- The filter uses walk, which was added in Pandoc 2.17
PANDOC_VERSION:must_be_at_least '2.17'

-- Enum for D2Theme
local D2Theme = {
NeutralDefault = 0,
Expand Down Expand Up @@ -196,6 +199,9 @@ local function render_graph(globalOptions)
print("Error: Unsupported format")
return nil
end
else
print("Error: Unsupported embed_mode")
return nil
end
end
end)
Expand Down
1 change: 1 addition & 0 deletions d2.lua