public ISpanned CreateHtmlString(string text, string defaultStyle, List <CssTag> customTags = null, bool mergeExistingStyles = true, bool includeExistingStyles = true) { var styles = customTags != null?MergeStyles(defaultStyle, customTags, mergeExistingStyles, includeExistingStyles) : _textStyles; if (!styles.ContainsKey(defaultStyle)) { styles.Add(defaultStyle, _textStyles[defaultStyle]); } var converter = new CustomHtmlParser(this, text, styles, defaultStyle); return(converter.Convert()); }
public ISpanned CreateHtmlString(string text, string defaultStyle, List <CssTag> customTags = null, bool mergeExistingStyles = true, bool includeExistingStyles = true) { var styles = customTags != null?MergeStyles(defaultStyle, customTags, mergeExistingStyles) : _textStyles; if (!styles.ContainsKey(defaultStyle)) { styles.Add(defaultStyle, _textStyles[defaultStyle]); } if (includeExistingStyles) { // Create a unique list of tags used within the text var tagList = new List <string>(); string pattern = @"(?<=</?)([^ >/]+)"; var matches = Regex.Matches(text, pattern); for (int i = 0; i < matches.Count; i++) { tagList.Add(matches[i].ToString()); } tagList = tagList.Distinct().ToList(); // If the tag isnt already included, add it into the styles foreach (var tag in tagList) { if (_textStyles.ContainsKey(tag) && !styles.ContainsKey(tag)) { styles.Add(tag, _textStyles[tag]); } } } var converter = new CustomHtmlParser(this, text, styles, defaultStyle); return(converter.Convert()); }