[add] show rule on raw
for examples
#35
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a show rule for
raw
elements with the languagesexample
(for Typst markup)examplec
(for Typst code mode)that will transform them into the code displayed side-by-side with the rendered output.
This addresses the third point in #32 .
Usage in documentation
In doc-comments, these languages are by default available. Note that the
preamble
is only applied to the markup versionexample
and not the code versionexamplec
since there is no good way to automatically convert the preamble between the two.Hidden code
It is possible to add hidden code that will be executed but not shown on lines starting with
>>>
. This is useful for import statements, wrapping everything inside a container of a fixed size and other things.This is inspired by the Typst documentation.
Standalone usage
This show rule can be used standalone via the function
render-examples()
.Scope
It also features a
scope
argument, that can be pre-setCustomization
The output format of the example can be customized through the parameter
layout
ofrender-examples
. This parameter takes afunction
with two positional arguments: theraw
element and the preview.Breaking change
In #15, this standalone example rendering was suggested. Before this PR, it was possible to write
This now breaks and should be replaced with the versions above.