/// <summary> /// Parses the specified textWithSubstitutes with source markup (according to set start and end tags) as preperation /// for getting subtitles and references texts. /// </summary> /// <param name="substitute">Substitute that replaces the source markdown.</param> private void Parse(IInteractiveSourceSubstitute substitute) { if (substitute == null) { return; } var pattern = new Regex(HtmlStartTag + ".+?" + HtmlEndTag); var match = pattern.Match(TextWithSubstitutes); int index = 0; while (match.Success) { string oldText = match.Value; string srcText = oldText; srcText = srcText.Replace(HtmlStartTag, string.Empty); srcText = srcText.Replace(HtmlEndTag, string.Empty); string sub = substitute.NextSubstitute(); Sources.Add(new Source(srcText, match.Index, sub, index)); // replace footnote markup with substitute TextWithSubstitutes = TextWithSubstitutes.Replace(oldText, sub); match = pattern.Match(TextWithSubstitutes); // working with new textWithSubstitutes to get correct start index index++; } }
/// <summary> /// Creates a parser for the specified textWithSubstitutes with source markup. /// </summary> /// <param name="textWithSubstitutes">TextWithSubstitutes to parse.</param> /// <param name="substitute">Substitute that replaces the source markdown.</param> public InteractiveSourcesParser(string textWithSubstitutes, IInteractiveSourceSubstitute substitute) { Sources = new List <Source>(); TextWithSubstitutes = textWithSubstitutes; Parse(substitute); }
/// <summary> /// Creates a parser for the specified textWithSubstitutes with source markup. /// </summary> /// <param name="substitute">Substitute that replaces the source markdown.</param> public InteractiveSourcesParser(IInteractiveSourceSubstitute substitute) { this.substitute = substitute; }