/// <summary> /// Creates a list. /// </summary> /// <param name="authoringEngine"></param> /// <param name="parentElement"></param> /// <param name="list"></param> /// <param name="attributes"></param> /// <returns></returns> private static DomElement CreateList(IAuthoringEngine authoringEngine, DomElement parentElement, Internal.List list, BlockElementAttributes attributes) { int index = 0; return(CreateListRecursive(authoringEngine, parentElement, list, ref index, list.Items[index].Qualifier, attributes)); }
/// <summary> /// Parses <paramref name="text"/> which is the child of <paramref name="parentElement"/>. /// </summary> /// <param name="authoringEngine"> /// The <see cref="IAuthoringEngine"/> which initiated the parsing process. /// </param> /// <param name="parentElement">Parent DOM element.</param> /// <param name="text">The text to be parsed.</param> public override void Parse(IAuthoringEngine authoringEngine, DomElement parentElement, string text) { if (NextElementParser != null) { NextElementParser.Parse(authoringEngine, parentElement, text); } }
/// <summary> /// Parses <paramref name="text"/> which is the child of <paramref name="parentElement"/>. /// </summary> /// <param name="authoringEngine"> /// The <see cref="IAuthoringEngine"/> which initiated the parsing process. /// </param> /// <param name="parentElement">Parent DOM element.</param> /// <param name="text">The text to be parsed.</param> public override void Parse(IAuthoringEngine authoringEngine, DomElement parentElement, string text) { Match match = Regex.Match(text); if (match.Success) { int startIndex = 0; while (match.Success) { // // Parsing prefix... if (startIndex < match.Index) { ParseWithNextElementParser(authoringEngine, parentElement, text.Substring(startIndex, match.Index - startIndex)); } // if ProcessMatch(authoringEngine, parentElement, match); startIndex = match.Index + match.Length; match = Regex.Match(text, startIndex); } // while ParseWithNextElementParser(authoringEngine, parentElement, text.Substring(startIndex)); } // if else { // // Proceed. ParseWithNextElementParser(authoringEngine, parentElement, text); } // else }
/// <summary> /// Template method which is invoked from <see cref="ElementParserBase.Parse"/> when /// a match is encountered. /// </summary> /// <param name="authoringEngine"></param> /// <param name="parentElement"></param> /// <param name="match"></param> protected override void ProcessMatch(IAuthoringEngine authoringEngine, DomElement parentElement, Match match) { Hyperlink hyperlink = new Hyperlink(parentElement, match.Groups["Text"].Value, match.Groups["Title"].Value, match.Groups["Url"].Value); parentElement.AppendChild(hyperlink); }
/// <summary> /// Template method which is invoked from <see cref="ElementParserBase.Parse"/> when /// a match is encountered. /// </summary> /// <param name="authoringEngine"></param> /// <param name="parentElement"></param> /// <param name="match"></param> protected override void ProcessMatch(IAuthoringEngine authoringEngine, DomElement parentElement, Match match) { TextBlock textBlock = new TextBlock(parentElement, InlineElementAttributes.Empty, match.Groups["Text"].Value, TextBlockFormatting.Unknown); parentElement.AppendChild(textBlock); }
/// <summary> /// Template method which is invoked from <see cref="ElementParserBase.Parse"/> when /// a match is encountered. /// </summary> /// <param name="authoringEngine"></param> /// <param name="parentElement"></param> /// <param name="match"></param> protected override void ProcessMatch(IAuthoringEngine authoringEngine, DomElement parentElement, Match match) { Acronym acronym = new Acronym(parentElement, match.Groups["Text"].Value, match.Groups["Acronym"].Value); parentElement.AppendChild(acronym); }
/// <summary> /// Template method which is invoked from <see cref="ElementParserBase.Parse"/> when /// a match is encountered. /// </summary> /// <param name="authoringEngine"></param> /// <param name="parentElement"></param> /// <param name="match"></param> protected override void ProcessMatch(IAuthoringEngine authoringEngine, DomElement parentElement, Match match) { FootnoteReference footnoteReference = new FootnoteReference(parentElement, Convert.ToInt32(match.Groups["FootnoteID"].Value)); parentElement.AppendChild(footnoteReference); }
/// <summary> /// Parses <paramref name="text"/> which is the child of <paramref name="parentElement"/> /// with <see cref="NextElementParser"/>, if any. /// </summary> /// <param name="authoringEngine"> /// The <see cref="IAuthoringEngine"/> which initiated the parsing process. /// </param> /// <param name="parentElement">Parent DOM element.</param> /// <param name="text">The text to be parsed.</param> protected void ParseWithNextElementParser(IAuthoringEngine authoringEngine, DomElement parentElement, string text) { if (NextElementParser != null) { NextElementParser.Parse(authoringEngine, parentElement, text); } }
/// <summary> /// Template method which is invoked from <see cref="ElementParserBase.Parse"/> when /// a match is encountered. /// </summary> /// <param name="authoringEngine"></param> /// <param name="parentElement"></param> /// <param name="match"></param> protected override void ProcessMatch(IAuthoringEngine authoringEngine, DomElement parentElement, Match match) { // // Processing the table. Table table = new Table(parentElement, CreateBlockElementAttributes(match)); parentElement.AppendChild(table); }
/// <summary> /// Template method which is invoked from <see cref="ElementParserBase.Parse"/> when /// a match is encountered. /// </summary> /// <param name="authoringEngine"></param> /// <param name="parentElement"></param> /// <param name="match"></param> protected override void ProcessMatch(IAuthoringEngine authoringEngine, DomElement parentElement, Match match) { Image image = new Image(parentElement, CreateBlockElementAttributes(match), match.Groups["Url"].Value, match.Groups["AlternateText"].Value); parentElement.AppendChild(image); }
/// <summary> /// Template method which is invoked from <see cref="ElementParserBase.Parse"/> when /// a match is encountered. /// </summary> /// <param name="authoringEngine"></param> /// <param name="parentElement"></param> /// <param name="match"></param> protected override void ProcessMatch(IAuthoringEngine authoringEngine, DomElement parentElement, Match match) { Internal.List list = new Internal.List(match); BlockElementAttributes attributes = CreateBlockElementAttributes(match); parentElement.AppendChild(CreateList(authoringEngine, parentElement, list, attributes)); }
/// <summary> /// Parses <paramref name="text"/> which is the child of <paramref name="parentElement"/>. /// </summary> /// <param name="authoringEngine"> /// The <see cref="IAuthoringEngine"/> which initiated the parsing process. /// </param> /// <param name="parentElement">Parent DOM element.</param> /// <param name="text">The text to be parsed.</param> public override void Parse(IAuthoringEngine authoringEngine, DomElement parentElement, string text) { // // Preparse implicit paragraphs. text = PreparseImplicitParagraphs(text); base.Parse(authoringEngine, parentElement, text); }
/// <summary> /// Template method which is invoked from <see cref="ElementParserBase.Parse"/> when /// a match is encountered. /// </summary> /// <param name="authoringEngine"></param> /// <param name="parentElement"></param> /// <param name="match"></param> protected override void ProcessMatch(IAuthoringEngine authoringEngine, DomElement parentElement, Match match) { Heading heading = new Heading(parentElement, CreateBlockElementAttributes(match), Convert.ToInt32(match.Groups["Level"].Value), match.Groups["Text"].Value); parentElement.AppendChild(heading); }
/// <summary> /// Template method which is invoked from <see cref="ElementParserBase.Parse"/> when /// a match is encountered. /// </summary> /// <param name="authoringEngine"></param> /// <param name="parentElement"></param> /// <param name="match"></param> protected override void ProcessMatch(IAuthoringEngine authoringEngine, DomElement parentElement, Match match) { Blockquote blockquote = new Blockquote(parentElement, CreateBlockElementAttributes(match)); parentElement.AppendChild(blockquote); ParseWithNextElementParser(authoringEngine, parentElement, match.Groups["Text"].Value); }
/// <summary> /// Template method which is invoked from <see cref="ElementParserBase.Parse"/> when /// a match is encountered. /// </summary> /// <param name="authoringEngine"></param> /// <param name="parentElement"></param> /// <param name="match"></param> protected override void ProcessMatch(IAuthoringEngine authoringEngine, DomElement parentElement, Match match) { Footnote footnote = new Footnote(parentElement, CreateBlockElementAttributes(match), Convert.ToInt32(match.Groups["FootnoteID"].Value)); parentElement.AppendChild(footnote); ParseWithNextElementParser(authoringEngine, footnote, match.Groups["Text"].Value); }
/// <summary> /// Template method which is invoked from <see cref="ElementParserBase.Parse"/> when /// a match is encountered. /// </summary> /// <param name="authoringEngine"></param> /// <param name="parentElement"></param> /// <param name="match"></param> protected override void ProcessMatch(IAuthoringEngine authoringEngine, DomElement parentElement, Match match) { // // ...paragraph itself... Paragraph paragraph = new Paragraph(parentElement, CreateBlockElementAttributes(match)); parentElement.AppendChild(paragraph); ParseWithNextElementParser(authoringEngine, paragraph, match.Groups["Text"].Value); }
private void InternalParse(IAuthoringEngine authoringEngine, DomElement parentElement, String text) { Match match = TextBlockRegex.Match(text); if (match.Success) { int startIndex = 0; while (match.Success) { // // What we have here is the text without any formatting. if (startIndex < match.Index) { ParseWithNextElementParser(authoringEngine, parentElement, text.Substring(startIndex, match.Index - startIndex)); } /*TextBlock prefixTextBlock = new TextBlock(parentElement, * InlineElementAttributes.Empty, startIndex < match.Index ? * text.Substring(startIndex, match.Index - startIndex) : string.Empty, * TextBlockFormatting.Unknown); * parentElement.AppendChild(prefixTextBlock);*/ // // Parsing match TextBlock textBlock = new TextBlock(parentElement, CreateInlineElementAttributes(match), string.Empty, GetTextBlockFormatting(match.Groups["Tag"].Value)); parentElement.AppendChild(textBlock); InternalParse(authoringEngine, textBlock, match.Groups["Text"].Value); startIndex = match.Index + match.Length; match = TextBlockRegex.Match(text, startIndex); } // while ParseWithNextElementParser(authoringEngine, parentElement, text.Substring(startIndex)); /* * parentElement.AppendChild(new TextBlock(parentElement, InlineElementAttributes.Empty, * text.Substring(startIndex), TextBlockFormatting.Unknown));*/ } // if else { ParseWithNextElementParser(authoringEngine, parentElement, text); /*parentElement.AppendChild(new TextBlock(parentElement, InlineElementAttributes.Empty, * text, TextBlockFormatting.Unknown));*/ } // else }
/// <summary> /// Recursively creates a list. /// </summary> /// <param name="authoringEngine"></param> /// <param name="parentElement"></param> /// <param name="list"></param> /// <param name="index"></param> /// <param name="previousQualifier"></param> /// <param name="attributes"></param> /// <returns></returns> private static DomElement CreateListRecursive(IAuthoringEngine authoringEngine, DomElement parentElement, Internal.List list, ref int index, string previousQualifier, BlockElementAttributes attributes) { // // Creating DOM object List domList = previousQualifier[previousQualifier.Length - 1] == '#' ? (List) new OrderedList(parentElement, attributes) : new UnorderedList(parentElement, attributes); // // Iterating through items. for (; index < list.Items.GetLength(0); ++index) { // // Creating DOM list item and adding it to the // list created above. ListItem listItem = new ListItem(domList, BlockElementAttributes.Empty); authoringEngine.ParseInlineElements(listItem, list.Items[index].Title); /*listItem.AppendChild(new TextBlock(listItem, InlineElementAttributes.Empty, * list.Items[index].Title, TextBlockFormatting.Unknown));*/ domList.AppendChild(listItem); if (index < list.Items.GetLength(0) - 1) { string nextQualifier = list.Items[index + 1].Qualifier; if (nextQualifier.Length != previousQualifier.Length) { if (nextQualifier.Length > previousQualifier.Length) { ++index; listItem.AppendChild(CreateListRecursive(authoringEngine, listItem, list, ref index, nextQualifier, BlockElementAttributes.Empty)); } // if else { break; } } // if } // if } // for return(domList); }
/// <summary> /// Parses <paramref name="text"/> which is the child of <paramref name="parentElement"/>. /// </summary> /// <param name="authoringEngine"> /// The <see cref="IAuthoringEngine"/> which initiated the parsing process. /// </param> /// <param name="parentElement">Parent DOM element.</param> /// <param name="text">The text to be parsed.</param> public override void Parse(IAuthoringEngine authoringEngine, DomElement parentElement, string text) { // // Unsecaping previously escaped characters. StringBuilder textBuilder = new StringBuilder(text); textBuilder.Replace("\\__", "__"); textBuilder.Replace("\\**", "**"); textBuilder.Replace("\\_", "_"); textBuilder.Replace("\\*", "*"); textBuilder.Replace("\\??", "??"); textBuilder.Replace("\\?", "?"); textBuilder.Replace("\\-", "-"); textBuilder.Replace("\\+", "+"); textBuilder.Replace("\\^", "^"); textBuilder.Replace("\\~", "~"); textBuilder.Replace("\\@", "@"); textBuilder.Replace("\\%", "%"); // // Replace double hyphens -- with an em-dash entity. textBuilder.Replace("--", "—"); // // Replace single hyphens surrounded by spaces with an en-dash entity. textBuilder.Replace(" - ", "–"); // // Replace triplets of periods with an ellipsis entity. textBuilder.Replace("...", "…"); // // Convert (TM), (R), and (C) to their respective HTML entities textBuilder.Replace("(TM)", "™"); textBuilder.Replace("(R)", "®"); textBuilder.Replace("(C)", "©"); // // Replacing simple quotes with angle quotes text = QuoteRegex.Replace(textBuilder.ToString(), "«${Text}»"); parentElement.AppendChild(new TextBlock(parentElement, InlineElementAttributes.Empty, text, TextBlockFormatting.Unknown)); }
/// <summary> /// Parses <paramref name="text"/> which is the child of <paramref name="parentElement"/>. /// </summary> /// <param name="authoringEngine"> /// The <see cref="IAuthoringEngine"/> which initiated the parsing process. /// </param> /// <param name="parentElement">Parent DOM element.</param> /// <param name="text">The text to be parsed.</param> public override void Parse(IAuthoringEngine authoringEngine, DomElement parentElement, string text) { authoringEngine.ParseInlineElements(parentElement, text); }
/// <summary> /// Adds <paramref name="blockElementParser"/> to the <paramref name="authoringEngine"/>. /// </summary> /// <param name="authoringEngine"></param> /// <param name="blockElementParser"></param> protected virtual void AddBlockElementParser(IAuthoringEngine authoringEngine, IBlockElementParser blockElementParser) { authoringEngine.AddBlockElementParser(blockElementParser); }
/// <summary> /// Adds <paramref name="inlineElementParser"/> to the <paramref name="authoringEngine"/>. /// </summary> /// <param name="authoringEngine"></param> /// <param name="inlineElementParser"></param> protected virtual void AddInlineElementParser(IAuthoringEngine authoringEngine, IInlineElementParser inlineElementParser) { authoringEngine.AddInlineElementParser(inlineElementParser); }
/// <summary> /// Parses <paramref name="text"/> which is the child of <paramref name="parentElement"/>. /// </summary> /// <param name="authoringEngine"> /// The <see cref="IAuthoringEngine"/> which initiated the parsing process. /// </param> /// <param name="parentElement">Parent DOM element.</param> /// <param name="text">The text to be parsed.</param> public override void Parse(IAuthoringEngine authoringEngine, DomElement parentElement, String text) { InternalParse(authoringEngine, parentElement, text); }
/// <summary> /// Parses <paramref name="text"/> which is the child of <paramref name="parentElement"/>. /// </summary> /// <param name="authoringEngine"> /// The <see cref="IAuthoringEngine"/> which initiated the parsing process. /// </param> /// <param name="parentElement">Parent DOM element.</param> /// <param name="text">The text to be parsed.</param> public abstract void Parse(IAuthoringEngine authoringEngine, DomElement parentElement, string text);
/// <summary> /// Template method which is invoked from <see cref="Parse"/> when /// a match is encountered. /// </summary> /// <param name="authoringEngine"></param> /// <param name="parentElement"></param> /// <param name="match"></param> protected virtual void ProcessMatch(IAuthoringEngine authoringEngine, DomElement parentElement, Match match) { }