Skip to content

Commit edce8c1

Browse files
authored
Allow substitutions in code blocks from global docset variables. (#685)
* Fix substitutions in code blocks * Fix naming
1 parent 2807814 commit edce8c1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

docs/syntax/substitutions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,9 @@ tar -xzf elasticsearch-{{version}}-linux-x86_64.tar.gz
4646
cd elasticsearch-{{version}}/
4747
```
4848

49+
```bash
50+
echo "{{a-global-variable}}"
51+
```
52+
4953

5054
Here is a variable with dashes: {{a-key-with-dashes}}

src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockParser.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,21 @@ private static void ProcessCallOuts(StringLineGroup lines, string language, Enha
147147

148148
var span = line.Slice.AsSpan();
149149

150-
if (span.ReplaceSubstitutions(context.YamlFrontMatter?.Properties, out var replacement))
150+
if (span.ReplaceSubstitutions(context.YamlFrontMatter?.Properties, out var frontMatterReplacement))
151151
{
152-
var s = new StringSlice(replacement);
152+
var s = new StringSlice(frontMatterReplacement);
153153
lines.Lines[index] = new StringLine(ref s);
154154
span = lines.Lines[index].Slice.AsSpan();
155155
}
156156

157+
if (span.ReplaceSubstitutions(context.Substitutions, out var globalReplacement))
158+
{
159+
var s = new StringSlice(globalReplacement);
160+
lines.Lines[index] = new StringLine(ref s);
161+
span = lines.Lines[index].Slice.AsSpan();
162+
}
163+
164+
157165
if (codeBlock.OpeningFencedCharCount > 3)
158166
continue;
159167

0 commit comments

Comments
 (0)