/// <summary> /// Returns a list of shortcodes. /// </summary> /// <param name="content"></param> /// <returns></returns> public List <Shortcode> GetShortcodes(string content) { ParseInternal(content); if (!ParseInstructions.Any()) { return(null); } return(ParseInstructions .Where(pi => !string.IsNullOrEmpty(pi.Tag)) .Select(pi => Create(pi.Tag, pi.Attributes, pi.Content)) .ToList()); }
public string Parse(string content) { ParseInternal(content); var contentBuilder = new StringBuilder(content); if (ParseInstructions.Any()) { var contentPositionAdjust = 0; var initialContentLength = contentBuilder.Length; foreach (var shortcodeInfo in ParseInstructions.OrderBy(pi => pi.BeginPosition)) { string generatedText = null; if (shortcodeInfo.Tag != null) { var shortcode = ShortcodeProvider.Create(shortcodeInfo.Tag, shortcodeInfo.Attributes, shortcodeInfo.Content); generatedText = shortcode.Generate(new ShortcodeContext { Tag = shortcodeInfo.Tag, Parser = this }); } else { generatedText = shortcodeInfo.PreCompiledContent; } if (generatedText == null) { generatedText = string.Empty; } var startIndex = shortcodeInfo.BeginPosition + contentPositionAdjust; if (startIndex < 0) { startIndex = 0; } contentBuilder.Remove(startIndex, shortcodeInfo.EndPosition - shortcodeInfo.BeginPosition); contentBuilder.Insert(startIndex, generatedText); contentPositionAdjust = contentBuilder.Length - initialContentLength; } } return(contentBuilder.ToString()); }