diff --git a/data/home/content/consulting/index.md b/data/home/content/consulting/index.md
index 3ffef2c..447c5f2 100644
--- a/data/home/content/consulting/index.md
+++ b/data/home/content/consulting/index.md
@@ -1,7 +1,7 @@
---
type: page
title: Consulting
-transformation: snark.replaceLinks
+transformation: snark.basic
language: en
---
@@ -21,7 +21,7 @@ Our research, which primarily includes open source projects, has already been ap
@@ -30,7 +30,7 @@ Our research, which primarily includes open source projects, has already been ap
@@ -39,7 +39,7 @@ Our research, which primarily includes open source projects, has already been ap
@@ -48,7 +48,7 @@ Our research, which primarily includes open source projects, has already been ap
diff --git a/src/main/kotlin/space/kscience/snark/SnarkPlugin.kt b/src/main/kotlin/space/kscience/snark/SnarkPlugin.kt
index 42d8f57..547b2ad 100644
--- a/src/main/kotlin/space/kscience/snark/SnarkPlugin.kt
+++ b/src/main/kotlin/space/kscience/snark/SnarkPlugin.kt
@@ -126,7 +126,7 @@ class SnarkPlugin : AbstractPlugin() {
"gif".asName() to SnarkParser(ImageIOReader, "gif"),
)
TextTransformation.TYPE -> mapOf(
- "replaceLinks".asName() to TextTransformation.replaceLinks
+ "basic".asName() to BasicTextTransformation
)
else -> super.content(target)
}
diff --git a/src/main/kotlin/space/kscience/snark/TextTransformation.kt b/src/main/kotlin/space/kscience/snark/TextTransformation.kt
index 2438d18..09f453c 100644
--- a/src/main/kotlin/space/kscience/snark/TextTransformation.kt
+++ b/src/main/kotlin/space/kscience/snark/TextTransformation.kt
@@ -10,10 +10,26 @@ fun interface TextTransformation {
companion object {
const val TYPE = "snark.textTransformation"
val TEXT_TRANSFORMATION_KEY = NameToken("transformation")
+ }
+}
- val replaceLinks: TextTransformation = object : TextTransformation {
- context(PageBuilder) override fun transform(text: String): String {
- return text.replace("\${homeRef}", homeRef)
+object BasicTextTransformation : TextTransformation {
+
+ private val regex = "\\\$\\{(\\w*)(?>\\(\"(.*)\"\\))?\\}".toRegex()
+
+ context(PageBuilder) override fun transform(text: String): String {
+ return text.replace(regex) { match ->
+ when (match.groups[1]!!.value) {
+ "homeRef" -> homeRef
+ "resolveRef" -> {
+ val refString = match.groups[2]?.value ?: error("resolveRef requires a string (quoted) argument")
+ resolveRef(refString)
+ }
+ "resolvePageRef" -> {
+ val refString = match.groups[2]?.value ?: error("resolvePageRef requires a string (quoted) argument")
+ resolvePageRef(refString)
+ }
+ else -> match.value
}
}
}