in source/dotnet/Library/AdaptiveCards/MarkedNet/MarkedNet/InlineLexer.cs [57:223]
public virtual string Output(string src)
{
var @out = String.Empty;
LinkObj link;
string text;
string href;
IList<string> cap;
while (!String.IsNullOrEmpty(src))
{
// escape
cap = this._rules.Escape.Exec(src);
if (cap.Any())
{
src = src.Substring(cap[0].Length);
@out += cap[1];
continue;
}
// autolink
cap = this._rules.AutoLink.Exec(src);
if (cap.Any())
{
src = src.Substring(cap[0].Length);
if (cap[2] == "@")
{
text = cap[1][6] == ':'
? this.Mangle(cap[1].Substring(7))
: this.Mangle(cap[1]);
href = this.Mangle("mailto:") + text;
}
else
{
text = this.EscapeHtml(cap[1]);
href = text;
}
@out += _options.Renderer.Link(href, null, text);
continue;
}
// url (gfm)
if (!this.inLink && (cap = this._rules.Url.Exec(src)).Any())
{
src = src.Substring(cap[0].Length);
text = this.EscapeHtml(cap[1]);
href = text;
@out += _options.Renderer.Link(href, null, text);
continue;
}
// tag
cap = this._rules.Tag.Exec(src);
if (cap.Any())
{
if (!this.inLink && Regex.IsMatch(cap[0], "^<a ", RegexOptions.IgnoreCase))
{
this.inLink = true;
}
else if (this.inLink && Regex.IsMatch(cap[0], @"^<\/a>", RegexOptions.IgnoreCase))
{
this.inLink = false;
}
src = src.Substring(cap[0].Length);
@out += this._options.Sanitize
? (this._options.Sanitizer != null)
? this._options.Sanitizer(cap[0])
: this.EscapeHtml(cap[0])
: cap[0];
continue;
}
// link
cap = this._rules.Link.Exec(src);
if (cap.Any())
{
src = src.Substring(cap[0].Length);
this.inLink = true;
@out += this.OutputLink(cap, new LinkObj
{
Href = cap[2],
Title = cap[3]
});
this.inLink = false;
continue;
}
// reflink, nolink
if ((cap = this._rules.RefLink.Exec(src)).Any() || (cap = this._rules.NoLink.Exec(src)).Any())
{
src = src.Substring(cap[0].Length);
var linkStr = (StringHelper.NotEmpty(cap, 2, 1)).ReplaceRegex(@"\s+", " ");
this.links.TryGetValue(linkStr.ToLower(), out link);
if (link == null || String.IsNullOrEmpty(link.Href))
{
@out += cap[0][0];
src = cap[0].Substring(1) + src;
continue;
}
this.inLink = true;
@out += this.OutputLink(cap, link);
this.inLink = false;
continue;
}
// strong
if ((cap = this._rules.Strong.Exec(src)).Any())
{
src = src.Substring(cap[0].Length);
@out += _options.Renderer.Strong(this.Output(StringHelper.NotEmpty(cap, 2, 1)));
continue;
}
// em
cap = this._rules.Em.Exec(src);
if (cap.Any())
{
src = src.Substring(cap[0].Length);
@out += _options.Renderer.Em(this.Output(StringHelper.NotEmpty(cap, 2, 1)));
continue;
}
// code
cap = this._rules.Code.Exec(src);
if (cap.Any())
{
src = src.Substring(cap[0].Length);
@out += _options.Renderer.Codespan(this.EscapeHtml(cap[2], true));
continue;
}
// br
cap = this._rules.Br.Exec(src);
if (cap.Any())
{
src = src.Substring(cap[0].Length);
@out += _options.Renderer.Br();
continue;
}
// del (gfm)
cap = this._rules.Del.Exec(src);
if (cap.Any())
{
src = src.Substring(cap[0].Length);
@out += _options.Renderer.Del(this.Output(cap[1]));
continue;
}
// text
cap = this._rules.Text.Exec(src);
if (cap.Any())
{
src = src.Substring(cap[0].Length);
@out += _options.Renderer.Text(this.EscapeHtml(this.Smartypants(cap[0])));
continue;
}
if (!String.IsNullOrEmpty(src))
{
throw new Exception("Infinite loop on byte: " + (int)src[0]);
}
}
return @out;
}