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

ENH Suggestion: Return the code as well as the diagram #6

Open
zachcp opened this issue Feb 2, 2024 · 3 comments
Open

ENH Suggestion: Return the code as well as the diagram #6

zachcp opened this issue Feb 2, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@zachcp
Copy link

zachcp commented Feb 2, 2024

This is a great addition to the ecosystem, thank you!

Is there a relatively easy way to retain the code so the code and the image are both viewable? Ideally I'd like to have the code in a folded code block as per other types of code. Do you think it would it be relatively straightforward to add this?

Thanks,
zach cp

@rcannood
Copy link
Member

rcannood commented Feb 2, 2024

Is the echo parameter what you are looking for? (See https://github.com/data-intuitive/quarto-d2?tab=readme-ov-file#attributes)

@zachcp
Copy link
Author

zachcp commented Feb 2, 2024

@rcannood Beautiful - I didn't see that.

So I just gave it a whirl and the code returns which is great, but it doesn't seem to respect Quarto's code-fold option. Do you know if there a way to get it to fold? (these can be long diagrams)

@rcannood
Copy link
Member

I see -- quarto-d2 would probably need to make use of https://github.com/quarto-dev/quarto-cli/blob/main/src/resources/filters/quarto-post/foldcode.lua. I'll leave this GitHub issue open for now.

@rcannood rcannood added the enhancement New feature or request label Mar 19, 2024
rcannood added a commit that referenced this issue Mar 20, 2024
* Add default SVG format for Typst output

Also add DarkMauve and DarkFlagshipTerrastruct as explicit theme options

* Remove duplicate theme

DarkMauve was already in the theme list

* Allow uppercase layout values

Also:

- Adds is_nonempty_string helper function
- Appends random number for diagram file name
- Use d2 file extension not txt for input
- Allow alternate syntax for attribute classes on code blocks

* Fix d2 class check

Also:

- Add support for reading d2 diagrams from external files using `file` parameter. Block text is ignored if file parameter is supplied.
- Add support for alternate code block syntax without curly braces.
- Insert rendered diagrams into the Pandoc mediabag when `embed_type="link"`
- Refactor to add helper functions `setPreD2RenderOptions` and `setD2RenderFormat`

* Update CHANGELOG.md

* Use d2-render instead of svg-convert for temp directory

* Add support for gif format

Also

- add animate_interval parameter
- drop setD2RenderFormat helper function
- use quarto.project.output_directory to set default folder
- revise check for d2 code block class
- replace codeblock text if file is provided
- add support for tala layout

* Use outputPath (not mediabag) if folder is supplied

* Update README

* Fix typo

* Fix error in inline embedding logic

* Add check for d2 or txt file extension in file option

Also:

- add check to see if file exists
- Improve handling of code block formatting (when echo=true)
- remove duplicative processing for options.pad and options.animate_interval

* Update README

* Add partial support for code folding (#6)

Based on https://github.com/shafayetShafee/add-code-files

* Add typst format tests w/ multiple diagram formats

Also add external d2 file to test file argument

* Update CHANGELOG.md

---------

Co-authored-by: Robrecht Cannoodt <[email protected]>
rcannood added a commit that referenced this issue Apr 3, 2024
* Add default SVG format for Typst output

Also add DarkMauve and DarkFlagshipTerrastruct as explicit theme options

* Remove duplicate theme

DarkMauve was already in the theme list

* Allow uppercase layout values

Also:

- Adds is_nonempty_string helper function
- Appends random number for diagram file name
- Use d2 file extension not txt for input
- Allow alternate syntax for attribute classes on code blocks

* Fix d2 class check

Also:

- Add support for reading d2 diagrams from external files using `file` parameter. Block text is ignored if file parameter is supplied.
- Add support for alternate code block syntax without curly braces.
- Insert rendered diagrams into the Pandoc mediabag when `embed_type="link"`
- Refactor to add helper functions `setPreD2RenderOptions` and `setD2RenderFormat`

* Update CHANGELOG.md

* Use d2-render instead of svg-convert for temp directory

* Add support for gif format

Also

- add animate_interval parameter
- drop setD2RenderFormat helper function
- use quarto.project.output_directory to set default folder
- revise check for d2 code block class
- replace codeblock text if file is provided
- add support for tala layout

* Use outputPath (not mediabag) if folder is supplied

* Update README

* Fix typo

* Fix error in inline embedding logic

* Add check for d2 or txt file extension in file option

Also:

- add check to see if file exists
- Improve handling of code block formatting (when echo=true)
- remove duplicative processing for options.pad and options.animate_interval

* Update README

* Add partial support for code folding (#6)

Based on https://github.com/shafayetShafee/add-code-files

* Add typst format tests w/ multiple diagram formats

Also add external d2 file to test file argument

* Update CHANGELOG.md

* fix typo (mt instead of mimetype)

Also reorder early return when file + cb text are nil

* Add `setD2outputPath` helper

Also:

- Simplify flow for setting mimetype
- rename setPreD2RenderOptions to setD2Options
- Protect against filename values w/ file extension
- Use assert consistently for errors
- Simplify flow for returning data or outputPath

* Correct typo in check for pdf format

* Fix typo in setD2outputPath

Also fixes issue w/ broken links inside Quarto projects + error outside of Quarto projects

---------

Co-authored-by: Robrecht Cannoodt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants