diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..136bf44 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +name: Test D2 Quarto Extension + +on: [push] + +jobs: + test_extension: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Quarto + uses: quarto-dev/quarto-actions/setup@v2 + + - name: Install D2 + run: curl -fsSL https://d2lang.com/install.sh | sh -s -- + + - name: Render Quarto document + run: | + cp -r _extensions tests + for file in $(find tests -name "*.qmd"); do + quarto render $file + done + + - name: Upload PDF artifact + uses: actions/upload-artifact@v4 + with: + name: rendered-output + path: tests diff --git a/tests/example.qmd b/tests/example.qmd new file mode 100644 index 0000000..83c3933 --- /dev/null +++ b/tests/example.qmd @@ -0,0 +1,87 @@ +--- +title: D2 Extension For Quarto +format: gfm +filters: + - d2 +d2: + layout: "elk" +--- + +This [Quarto](https://quarto.org) extension allows you to render [D2](https://d2lang.com) diagrams directly within your markdown documents. + +Main features: + +- Render [D2](https://d2lang.com) diagrams directly within your [Quarto](https://quarto.org) markdown documents. +- Control the appearance and layout of your diagrams using global settings or code block attributes. +- Tune the width and height of the resulting figures using the "width" and "height" arguments. + +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 + + +```{.d2 width="50%" echo="true"} +logs: { + shape: page + style.multiple: true +} +user: User {shape: person} +network: Network { + tower: Cell Tower { + satellites: { + shape: stored_data + style.multiple: true + } + + satellites -> transmitter + satellites -> transmitter + satellites -> transmitter + transmitter + } + processor: Data Processor { + storage: Storage { + shape: cylinder + style.multiple: true + } + } + portal: Online Portal { + UI + } + + tower.transmitter -> processor: phone logs +} +server: API Server + +user -> network.tower: Make call +network.processor -> server +network.processor -> server +network.processor -> server + +server -> logs +server -> logs +server -> logs: persist + +server -> network.portal.UI: display +user -> network.portal.UI: access { + style.stroke-dash: 3 +} +``` diff --git a/example.qmd b/tests/global.qmd similarity index 100% rename from example.qmd rename to tests/global.qmd diff --git a/tests/interactive.qmd b/tests/interactive.qmd new file mode 100644 index 0000000..ec7a916 --- /dev/null +++ b/tests/interactive.qmd @@ -0,0 +1,19 @@ +--- +title: "D2 Example" +format: html +filters: + - d2 +d2: + format: svg + embed_mode: raw +--- + +```{.d2 width="40%"} +x { + link: "https://quarto.org" +} +y { + tooltip: "This is a tooltip" +} +x -> y -> z +``` diff --git a/tests/minimum.qmd b/tests/minimum.qmd new file mode 100644 index 0000000..2b692e9 --- /dev/null +++ b/tests/minimum.qmd @@ -0,0 +1,9 @@ +--- +title: "D2 Example" +filters: + - d2 +--- + +```{.d2} +x -> y +```