private static string GenerateUniqueHeaderID(ParseData data, string text) { text = text.ToLower().Replace(' ', '-'); text = Regex.Replace(text, @"[^0-9a-z\-]", ""); text = Regex.Replace(text, @"\-{2,}", "-"); if (text.Length < 3) { text = "h" + Guid.NewGuid().ToString("N").Substring(6, 12).ToLower(); } if (Char.IsDigit(text[0])) { text = "_" + text; } const string key = nameof(MdHeadingElement) + ".IdList"; var list = data.Get(key, () => new List <string>()); var id = text; var num = 2; while (list.Contains(id)) { id = text + "-" + num++; } list.Add(id); return(id); }
private static INode ResolveCell(string text, Parser parser, ParseData data, string scope) { var res = Regex.Match(text.Trim(), "^:ref=([a-z ]+)$", RegexOptions.IgnoreCase); if (res.Success) { var name = res.Groups[1].Value; var node = data.Get <INode>($"Ref::{name}", () => null); if (node != null) { return(node); } } return(parser.ParseTags(data, text, scope, "inline")); }