private static bool Parse(DomElement parentElement, AuthoringScope authoringScope, string text,
                                  Regex regex, TextBlockModifier expectedModifier)
        {
            Match match = regex.Match(text);

            if (match.Success)
            {
                //
                // Parsing prefix...
                ParsePrefix(parentElement, authoringScope, text, match);

                //
                // ...text block itself...
                TextBlock textBlock = new TextBlock(parentElement, CreateInlineElementAttributes(match),
                                                    match.Groups["Text"].Value, expectedModifier);
                parentElement.AppendChild(textBlock);

                //
                // ...and finally parse suffux
                ParseSuffix(parentElement, authoringScope, text, match);
                return(true);
            } // if

            return(false);
        }
Example #2
0
        /// <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);
        }
Example #4
0
        /// <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);
        }
Example #5
0
        /// <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)
        {
            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>
        /// 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)
        {
            //
            // 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)
        {
            Footnote footnote = new Footnote(parentElement, CreateBlockElementAttributes(match),
                                             Convert.ToInt32(match.Groups["FootnoteID"].Value));

            parentElement.AppendChild(footnote);

            ParseWithNextElementParser(authoringEngine, footnote, match.Groups["Text"].Value);
        }
Example #11
0
        /// <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>
        /// Parses <paramref name="text"/> which is the child of <paramref name="parentElement"/> in
        /// accordance with <paramref name="authoringScope"/>.
        /// </summary>
        /// <param name="parentElement">Parent DOM element.</param>
        /// <param name="authoringScope">Authoring scope.</param>
        /// <param name="text">The text to be parsed.</param>
        public override void Parse(DomElement parentElement, AuthoringScope authoringScope, string text)
        {
            if (Parse(parentElement, authoringScope, text, StrongEmphasisRegex, TextBlockModifier.StrongEmphasis))
            {
                return;
            }

            if (Parse(parentElement, authoringScope, text, ItalicsRegex, TextBlockModifier.Italics))
            {
                return;
            }

            if (Parse(parentElement, authoringScope, text, EmphasisRegex, TextBlockModifier.Emphasis))
            {
                return;
            }

            if (Parse(parentElement, authoringScope, text, BoldRegex, TextBlockModifier.Bold))
            {
                return;
            }

            if (Parse(parentElement, authoringScope, text, CitationRegex, TextBlockModifier.Citation))
            {
                return;
            }

            if (Parse(parentElement, authoringScope, text, DeletedRegex, TextBlockModifier.Deleted))
            {
                return;
            }

            if (Parse(parentElement, authoringScope, text, InsertedRegex, TextBlockModifier.Inserted))
            {
                return;
            }

            if (Parse(parentElement, authoringScope, text, SuperscriptRegex, TextBlockModifier.Superscript))
            {
                return;
            }

            if (Parse(parentElement, authoringScope, text, SubscriptRegex, TextBlockModifier.Subscript))
            {
                return;
            }

            if (Parse(parentElement, authoringScope, text, SpanRegex, TextBlockModifier.Unknown))
            {
                return;
            }

            parentElement.AppendChild(new TextBlock(parentElement, InlineElementAttributes.Empty,
                                                    text, TextBlockModifier.Unknown));
        }
        /// <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);
        }
        /// <summary>
        /// Returns a literal object for the text between HtmlStart (the last position of the end of a tag) and the current position.
        /// If !AllowLiterals then it's wrapped in a span.
        /// </summary>
        /// <param name="current"></param>
        /// <returns></returns>
        protected IDomObject GetLiteral(IterationData current)
        {
            // There's plain text -return it as a literal.

            IDomObject textObj;
            DomText    lit;

            if (current.Invalid)
            {
                lit = new DomInvalidElement();
            }
            else if (current.ReadTextOnly)
            {
                current.ReadTextOnly = false;
                lit = new DomInnerText();
            }
            else
            {
                lit = new DomText();
            }

            if (isBound)
            {
                lit.SetTextIndex(Document, Document.TokenizeString(current.HtmlStart, current.Pos - current.HtmlStart));
            }
            else
            {
                string text = BaseHtml.SubstringBetween(current.HtmlStart, current.Pos);
                lit.NodeValue = Objects.HtmlDecode(text);
            }

            if (!current.AllowLiterals)
            {
                IDomElement wrapper = new DomElement("span");
                wrapper.AppendChild(lit);
                textObj = wrapper;
            }
            else
            {
                textObj = lit;
            }

            if (current.Parent != null)
            {
                current.Parent.Element.AppendChild(textObj);
                current.Reset();
                return(null);
            }
            else
            {
                current.Finished = true;
                return(textObj);
            }
        }
Example #15
0
        void SetCustomCss()
        {
            var mainDocument = Widget.MainFrameDocument ?? Widget.MainFrame.DomDocument;
            var head         = mainDocument?.DocumentElement?.GetElementsByTagName("head")? [0];

            if (head == null)
            {
                customCssNode = null;
                return;
            }

            // reuse node reference only if the document did not change and still contains the injected node
            if (customCssNode != null && !head.ChildNodes.Contains(customCssNode))
            {
                customCssNode = null;
            }

            if (!string.IsNullOrEmpty(CustomCss))
            {
                if (customCssNode == null)
                {
                    customCssNode = mainDocument.CreateElement("style");
                    customCssNode.SetAttribute("type", "text/css");
                    if (head.ChildNodes.Count > 0)
                    {
                        head.InsertBefore(customCssNode, head.FirstChild);
                    }
                    else
                    {
                        head.AppendChild(customCssNode);
                    }
                }
                if (customCssNode.FirstChild != null)
                {
                    customCssNode.ReplaceChild(mainDocument.CreateTextNode(customCss), customCssNode.FirstChild);
                }
                else
                {
                    customCssNode.AppendChild(mainDocument.CreateTextNode(customCss));
                }
            }
            else if (customCssNode != null)
            {
                if (head.ChildNodes.Contains(customCssNode) == true)
                {
                    head.RemoveChild(customCssNode);
                }
                customCssNode.Dispose();
                customCssNode = null;
            }
        }
Example #16
0
        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>
        /// 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("--", "&mdash;");

            //
            // Replace single hyphens surrounded by spaces with an en-dash entity.
            textBuilder.Replace(" - ", "&ndash;");

            //
            // Replace triplets of periods with an ellipsis entity.
            textBuilder.Replace("...", "&hellip;");

            //
            // Convert (TM), (R), and (C) to their respective HTML entities
            textBuilder.Replace("(TM)", "&trade;");
            textBuilder.Replace("(R)", "&reg;");
            textBuilder.Replace("(C)", "&copy;");

            //
            // Replacing simple quotes with angle quotes
            text = QuoteRegex.Replace(textBuilder.ToString(), "&laquo;${Text}&raquo;");

            parentElement.AppendChild(new TextBlock(parentElement, InlineElementAttributes.Empty,
                                                    text, TextBlockFormatting.Unknown));
        }
        /// <summary>
        /// Returns a literal object for the text between HtmlStart (the last position of the end of a tag) and the current position.
        /// If !AllowLiterals then it's wrapped in a span.
        /// </summary>
        /// <param name="current"></param>
        /// <returns></returns>
        protected IDomObject GetLiteral(IterationData current)
        {
            // There's plain text -return it as a literal.

            IDomObject textObj;
            DomText lit;
            if (current.Invalid) {
                lit = new DomInvalidElement();
            }
            else if (current.ReadTextOnly)
            {
                current.ReadTextOnly = false;
                lit = new DomInnerText();
            } else {
                lit = new DomText();
            }

            if (isBound)
            {
                lit.SetTextIndex(Document, Document.TokenizeString(current.HtmlStart, current.Pos - current.HtmlStart));
            }
            else
            {
                string text = BaseHtml.SubstringBetween(current.HtmlStart, current.Pos);
                lit.NodeValue = Objects.HtmlDecode(text);
            }

            if (!current.AllowLiterals)
            {
                IDomElement wrapper = new DomElement("span");
                wrapper.AppendChild(lit);
                textObj = wrapper;
            }
            else
            {
                textObj = lit;
            }

            if (current.Parent != null)
            {
                current.Parent.Element.AppendChild(textObj);
                current.Reset();
                return null;
            }
            else
            {
                current.Finished = true;
                return textObj;
            }
        }
Example #19
0
 public override void AddChildElement(IModelElementInstance extensionElement)
 {
     DomElement.AppendChild(extensionElement.DomElement);
 }
 public void SetValue <T>(T value) where T : IBpmnModelElementInstance
 {
     RemoveValue();
     DomElement.AppendChild(value.DomElement);
 }