Skip to content

Commit 2c73209

Browse files
fix when to resolve subs
1 parent b6d66fb commit 2c73209

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,29 @@ private static void ParseStylingInstructions(LinkInline link, ParserContext cont
7575
return;
7676

7777
var attributes = link.GetAttributes();
78+
var title = link.Title;
7879

79-
if (string.IsNullOrWhiteSpace(link.Title) || link.Title.IndexOf('=') < 0)
80-
link.Title = (link.Title ?? "{undefined}").ReplaceSubstitutions(context);
81-
82-
var matches = LinkRegexExtensions.MatchTitleStylingInstructions().Match(link.Title);
83-
if (!matches.Success)
80+
if (string.IsNullOrEmpty(title))
8481
return;
8582

86-
var width = matches.Groups["width"].Value;
87-
if (!width.EndsWith('%'))
88-
width += "px";
89-
var height = matches.Groups["height"].Value;
90-
if (string.IsNullOrEmpty(height))
91-
height = width;
92-
else if (!height.EndsWith('%'))
93-
height += "px";
94-
95-
attributes.AddProperty("width", width);
96-
attributes.AddProperty("height", height);
83+
var matches = LinkRegexExtensions.MatchTitleStylingInstructions().Match(title);
84+
if (matches.Success)
85+
{
86+
var width = matches.Groups["width"].Value;
87+
if (!width.EndsWith('%'))
88+
width += "px";
89+
var height = matches.Groups["height"].Value;
90+
if (string.IsNullOrEmpty(height))
91+
height = width;
92+
else if (!height.EndsWith('%'))
93+
height += "px";
94+
95+
attributes.AddProperty("width", width);
96+
attributes.AddProperty("height", height);
97+
98+
title = title[..matches.Index];
99+
}
100+
link.Title = (title ?? "{undefined}").ReplaceSubstitutions(context);
97101
}
98102

99103
private static bool IsInCommentBlock(LinkInline link) =>
@@ -182,7 +186,7 @@ private static void ProcessCrossLink(LinkInline link, InlineProcessor processor,
182186
s => processor.EmitError(link, s),
183187
s => processor.EmitWarning(link, s),
184188
uri, out var resolvedUri)
185-
)
189+
)
186190
link.Url = resolvedUri.ToString();
187191
}
188192

0 commit comments

Comments
 (0)