Skip to content

Commit

Permalink
Normalize substitution keys to be case-insensitive. (#380)
Browse files Browse the repository at this point in the history
Substitution keys are now consistently converted to lowercase to ensure case-insensitive matching. This avoids potential mismatches caused by differing key casing in configurations and front matter.
  • Loading branch information
Mpdreamz authored Jan 30, 2025
1 parent 12f9ed1 commit a771e8c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Elastic.Markdown/Myst/ParserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ public ParserContext(
Configuration = configuration;

foreach (var (key, value) in configuration.Substitutions)
Properties[key] = value;
Properties[key.ToLowerInvariant()] = value;

if (frontMatter?.Properties is { } props)
{
foreach (var (key, value) in props)
foreach (var (k, value) in props)
{
var key = k.ToLowerInvariant();
if (configuration.Substitutions.TryGetValue(key, out _))
this.EmitError($"{{{key}}} can not be redeclared in front matter as its a global substitution");
else
Properties[key] = value;
}

}

if (frontMatter?.Title is { } title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice)
startPosition -= openSticks;
startPosition = Math.Max(startPosition, 0);

var key = content.ToString().Trim(['{', '}']);
var key = content.ToString().Trim(['{', '}']).ToLowerInvariant();
var found = false;
var replacement = string.Empty;
if (processor.Context?.Properties.TryGetValue(key, out var value) ?? false)
Expand Down

0 comments on commit a771e8c

Please sign in to comment.