I would like to implement Asciidoc-like Callouts (Callouts | Asciidoctor Docs). In order to do so, I process the raw blocks for // 1 style comments and replace them with ① circled numbers. It’s actually quite straightforward:
#show raw.where(block: true): it => {
set text(size: 1.25em) // fix https://github.com/typst/typst/issues/1331
it = it.text.replace(regex("// \((\d+)\)"),
i => str.from-unicode(9311 + int(i.captures.at(0))))
// endless loop
raw(it, block: true, lang: "java")
}
I get the error maximum show rule depth exceeded which it seems is an endless loop because it tries to reapply the show rule over and over again even after the replacement. With (raw(it, lang: "java")) it already works, but this is no code block, it’s inline raw code.
How to circumvent the endless loop (maximum show rule depth exceeded)?
You should use a nested show rule to do the replacement you want. That way you don’t have to call raw() again which will cause an infinite loop, as you already noticed yourself.
#show raw.where(block: true): it => {
show regex("// \((\d+)\)"): it => {
// do your string replacement here
}
it
}
Hey @gpr, welcome to the forum! I’ve added some tags and also changed your question post’s title to better fit our guidelines: How to post in the Questions category
For future posts, make sure your title is a question you’d ask to a friend about Typst.
In addition, if @janekfleper’s answer helped you, make sure to mark it as a solution. If not, let us know if you have further questions!
Thanks, it works great for normal raw blocks without syntax highlighting:
#show raw.where(block: true): rawblock => {
show regex("// <(\d+)>"): match => {
match.text.replace(regex("// <(\d+)>"),
i => str.from-unicode(9311 + int(i.captures.at(0))))
}
rawblock
// repr(rawblock)
}
```
public class HelloWorld { // <1>
public static void main(String[] args) { // <2>
System.out.println("Hello, World!"); // <3>
}
}
```
#set enum(numbering: "①")
+ The class name is `HelloWorld`
+ This is the method signature
+ This is the call to `stdout`
I find, it fits nicely with the numbered list with circled numbers .
But unfortunately it breaks when trying to use syntax highlighted code:
```java
public class HelloWorld { // <1>
public static void main(String[] args) { // <2>
System.out.println("Hello, World!"); // <3>
}
}
```
The only solution I can think of is to use an additional show rule that hides the forward slashes and to reduce the regex show rule to only match <1>. This is of course far from an elegant solution…
#show raw.where(block: true, lang: "java"): it => {
show "//": ""
show regex(" <(\d+)>"): it => {
// do your string replacement here
}
it
}
Thanks, so this actually works. Maybe someone finds this via Google, here is the code:
#show raw.where(block: true): rawblock => {
show "//": ""
show regex(" <(\d+)>"): match => {
match.text.replace(regex(" <(\d+)>"),
i => str.from-unicode(9311 + int(i.captures.at(0))))
}
rawblock
}
'``java
public class HelloWorld { // <1>
public static void main(String[] args) { // <2>
System.out.println("Hello, World!"); // <3>
} // <4>
} // <5>
'``
#set enum(numbering: "①")
+ The class name is `HelloWorld`
+ This is the method signature
+ This is the call to `stdout`